Leetcode 1411 Solution

This article provides solution to leetcode question 1411 (convert-binary-number-in-a-linked-list-to-integer)

https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer

Solution

# 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:
        val = 0
        node = head
        while node:
            val = val * 2 + node.val
            node = node.next

        return val