Solved at: 2022-09-25
head which is a reference node to a singly-linked list. The value of each node in the linked list is either
1. The linked list holds the binary representation of a number.
Return the decimal value of the number in the linked list.
The most significant bit is at the head of the linked list.
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
def getDecimalValue(self, head: ListNode) -> int:
value = head.val
value *= 2
head = head.next
value += head.val
- 60 ms, faster than 28.54% of Python3 online submissions for Convert Binary Number in a Linked List to Integer.
- 13.9 MB, less than 9.10% of Python3 online submissions for Convert Binary Number in a Linked List to Integer.
- Time complexity:
- Space complexity: