714. Binary Number to Integer Conversion
0
Medium
Given a reference node called *head* that points to a singly-linked list, where each node contains either a 0 or a 1, the linked list represents a binary number.
Your task is to print the decimal value of the binary number represented by the linked list.
The most significant bit is located at the head of the linked list.
You can refer to the following link to understand how to convert a binary number to a decimal value: https://www.wikihow.com/Convert-from-Binary-to-Decimal
Your task is to print the decimal value of the binary number represented by the linked list.
The most significant bit is located at the head of the linked list.
You can refer to the following link to understand how to convert a binary number to a decimal value: https://www.wikihow.com/Convert-from-Binary-to-Decimal
Input Format
The first line contains the length of the Linked List, N.
The second line contains N nodes of the Linked List.
The second line contains N nodes of the Linked List.
Output Format
Print the decimal value of the number in the Linked List.
Example
Input
3
1 0 1
Output
5
Constraints
The Linked List must not be empty.
The number of nodes in the Linked List should not exceed 30.
Each node's value must be either 0 or 1.
The number of nodes in the Linked List should not exceed 30.
Each node's value must be either 0 or 1.
Loading...
View Submissions
Console