Skip to content

Commit 99f1d53

Browse files
authored
Merge pull request #2232 from Donghae0230/main
[Donghae0230] WEEK 07 solutions
2 parents 3feceac + fb07b62 commit 99f1d53

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

reverse-linked-list/Donghae0230.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
8+
temp = []
9+
while head:
10+
temp.append(int(head.val))
11+
head = head.next
12+
temp = list(reversed(temp))
13+
print(temp)
14+
15+
dummy = ListNode(0)
16+
tail = dummy
17+
for i in temp:
18+
# print(i, tail)
19+
tail.next = ListNode(i)
20+
tail = tail.next
21+
# print(dummy)
22+
return dummy.next

0 commit comments

Comments
 (0)