FunctionRacerProblemsRace

Binary Linked List to Integer

BeginnerLinked listsPython, JavaScript, TypeScript, Java, C++

Each node holds a 0 or a 1, and the list spells a binary number with the head as the most significant bit. Return its value in decimal. An empty list means 0. The list is passed in as head.

Linked lists appear in the tests as the list of their values, like [1,2,3]. Each node is a ListNode with .val and .next; the class is already defined for you.

Example 1

head [1,0,1]
returns 5

101 in binary is 5.

Example 2

head [0,0,1,1]
returns 3

0011 in binary is 3.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Linked lists problems