-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path94.py
More file actions
29 lines (25 loc) · 696 Bytes
/
94.py
File metadata and controls
29 lines (25 loc) · 696 Bytes
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
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def doubleIt(self, head: Optional[ListNode]) -> Optional[ListNode]:
num = ""
node = head
while node != None:
num += f"{node.val}"
node = node.next
num = num[::-1]
res = None
tmp = None
tmp2 = 0
for v in num:
x = int(v) * 2
res = ListNode((x % 10) + tmp2, tmp)
tmp = res
tmp2 = x // 10
if tmp2 != 0:
tmp = res
res = ListNode(tmp2, tmp)
return res