Skip to content
LC-1290 Easy LeetCode

1290. Convert Binary Number in a Linked List to Integer

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 81% Topics: Linked List, Math
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

# Definition for singly-linked list.
class ListNode(object):
    def __init__(self, x):
        self.val = x
        self.next = None


class Solution(object):
    def getDecimalValue(self, head):
        """
        :type head: ListNode
        :rtype: int
        """
        result = 0
        while head: 
            result = result*2 + head.val 
            head = head.next 
        return result

Solution from kamyu104/LeetCode-Solutions · MIT