Skip to content

Commit a82617b

Browse files
committed
feat: Solve reverse-linked-list problem
1 parent ca90209 commit a82617b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
ย (0)