-
-
Notifications
You must be signed in to change notification settings - Fork 297
/
Copy path1290.py
33 lines (29 loc) · 1 KB
/
1290.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
__________________________________________________________________________________________________
sample 12 ms submission
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def getDecimalValue(self, head: ListNode) -> int:
num = 0
while head:
num = 2 * num + head.val
head = head.next
return num
__________________________________________________________________________________________________
sample 16 ms submission
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def getDecimalValue(self, head: ListNode) -> int:
output= 0
while head:
output = (output << 1) | head.val
head = head.next
return output
__________________________________________________________________________________________________