Given head, a reference to the head node of a singly linked list in which every node holds 0 or 1, the list is the binary representation of a number with the most significant bit at the head. Return the decimal value of that number.
Given head, a reference to the head node of a singly linked list in which every node holds 0 or 1, the list is the binary representation of a number with the most significant bit at the head. Return the decimal value of that number.
Example 1:
Input: {"head":[1,0,1]}
Output: 5
Constraints:
The linked list is not empty.
The number of nodes will not exceed 30.
Each node's value is either 0 or 1.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"head":[1,0,1]}
Start with num = 0 and point node at the head. The head holds the most significant bit.