### Problem
The nonempty singly linked list begins with its most significant binary digit. Every node value is 0 or 1. Return the represented integer in decimal, reading head to tail.
```cpp
class Solution {
public:
int getDecimalValue(ListNode* head);
};
```
### Examples
**Example 1:**
```text
Input: head = [1,1,0]
Output: 6
Explanation: Binary110 equals4+2=6.
```
**Example 2:**
```text
Input: head = [0,0,1,1]
Output: 3
Explanation: Leading zeros do not change the value of binary0011.
```
### Constraints
- The linked list is nonempty and has at most 30 nodes.
- Every node contains 0 or 1.
### Contract considerations
Retain `ListNode* head`; the example arrays display node values and do not replace the native linked-list API.
```hint Read the boundary condition
Which end holds the most significant digit, and are leading zero-valued nodes allowed?
```
### Boundary reminders
Retain `ListNode* head`; the example arrays display node values and do not replace the native linked-list API.
Overview: Read a Binary Integer From Native List Nodes. The nonempty singly linked list begins with its most significant binary digit.
The nonempty singly linked list begins with its most significant binary digit. Every node value is 0 or 1. Return the represented integer in decimal, reading head to tail.
class Solution {
public:
int getDecimalValue(ListNode* head);
};
Examples
Example 1:
Input: head = [1,1,0]
Output: 6
Explanation: Binary110 equals4+2=6.
Example 2:
Input: head = [0,0,1,1]
Output: 3
Explanation: Leading zeros do not change the value of binary0011.
Constraints
The linked list is nonempty and has at most 30 nodes.
Every node contains 0 or 1.
Contract considerations
Retain ListNode* head; the example arrays display node values and do not replace the native linked-list API.
Boundary reminders
Retain ListNode* head; the example arrays display node values and do not replace the native linked-list API.