We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e75b852 commit aba52c3Copy full SHA for aba52c3
1 file changed
reverse-linked-list/hyeri0903.py
@@ -0,0 +1,31 @@
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
+
9
+ if head is None:
10
+ return None
11
12
+ st = []
13
+ cur = head
14
15
+ while cur:
16
+ st.append(cur.val)
17
+ cur = cur.next
18
19
+ dummy = ListNode(0)
20
+ cur = dummy
21
22
+ while st:
23
+ cur_value = st.pop()
24
+ cur.next = ListNode(cur_value)
25
26
27
+ return dummy.next
28
29
30
31
0 commit comments