1290. Convert Binary Number in a Linked List to Integer

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1290

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def getDecimalValue(self, head: ListNode) -> int:
        res = 0
        while head:
            res = res << 1 | head.val
            head = head.next
        return res