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 ca90209 commit a82617bCopy full SHA for a82617b
โreverse-linked-list/hu6r1s.pyโ
@@ -0,0 +1,24 @@
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
+ """
8
+ ๋งํฌ๋ ๋ฆฌ์คํธ ํ์ต์ ๋ฐ๋ก ํด์ผํ ํ์์ฑ์ด ์์
9
10
+ def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
11
+ stack = []
12
+ node = head
13
+ while node:
14
+ stack.append(node)
15
+ node = node.next
16
+
17
+ dummy = ListNode()
18
+ output = dummy
19
+ while stack:
20
+ output.next = stack.pop()
21
+ output = output.next
22
23
+ output.next = None
24
+ return dummy.next
0 commit comments