Skip to content

Latest commit

 

History

History
22 lines (20 loc) · 548 Bytes

1290.md

File metadata and controls

22 lines (20 loc) · 548 Bytes

1290. Convert Binary Number in a Linked List to Integer

Solution 1 (time O(n), space O(1))

# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution(object):
    def getDecimalValue(self, head):
        """
        :type head: ListNode
        :rtype: int
        """
        ans = 0
        while head:
            ans = ans * 2 + head.val
            head = head.next
        return ans