Convert a binary number stored in a linked list into its decimal integer value.
You are given the head of a singly linked list where each node contains either 0 or 1. The linked list represents a binary number, with the most significant bit at the head of the list and the least significant bit at the tail.
Write a function that returns the decimal integer value of the binary number represented by the linked list.
For example, the list 1 -> 0 -> 1 represents binary 101, which is decimal 5.
0 or 1.0 or 1.A singly linked list head node where each node contains a binary digit (0 or 1).
Return the decimal integer value represented by the linked list.
0 or 1.Example 1
Input
head = [1,0,1]
Output
5
Explanation
Binary 101 equals decimal 5.
Example 2
Input
head = [0]
Output
0
Explanation
Binary 0 equals decimal 0.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.