← 返回 cisco 的题目列表Linked List Binary to Decimal
类型:qbank
Create or traverse a singly linked list whose node values are binary digits and print the corresponding base-10 decimal value.
Requirements
Input line 1 is list_size, the number of nodes N.
Input line 2 contains N space-separated integers, each 0 or 1, representing node data in list order.
Build or traverse the linked list and convert the binary representation to a decimal integer.
Constraint shown: 1 <= N <= 64.
Print the decimal form of the binary input.
Examples
Input:
7
0 0 1 1 0 1 0
Output:
26
Explanation: the list represents binary 0011010, which is decimal 26.
Notes
The candidate who shared this prompt had one hidden linked-list test case fail, so handle leading zeros and the full N <= 64 range carefully.