Advertisement
DeepRest

Convert Binary Number in a Linked List to Integer

Dec 7th, 2021
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.35 KB | None | 0 0
  1. # Definition for singly-linked list.
  2. # class ListNode:
  3. #     def __init__(self, val=0, next=None):
  4. #         self.val = val
  5. #         self.next = next
  6. class Solution:
  7.     def getDecimalValue(self, head: ListNode) -> int:
  8.         res, curr = head.val, head
  9.         while curr := curr.next:
  10.             res = (res<<1) | curr.val
  11.         return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement