Skip to content

Commit 261ab90

Browse files
committed
refactor: Remove example comments
1 parent 854537f commit 261ab90

File tree

1 file changed

+29
-51
lines changed

1 file changed

+29
-51
lines changed

โ€Žreorder-list/KwonNayeon.pyโ€Ž

Lines changed: 29 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
- ํฌ์ธํ„ฐ๋“ค์„ ๋ฒˆ๊ฐˆ์•„๊ฐ€๋ฉฐ ์—ฐ๊ฒฐํ•จ
2222
2323
๋…ธํŠธ:
24-
- ํฌ์ธํ„ฐ ์กฐ์ž‘(์—ฐ๊ฒฐ๋ฆฌ์ŠคํŠธ ๋’ค์ง‘๊ธฐ, ๋ณ‘ํ•ฉ) ๋ฐฉ๋ฒ•์„ ๋‹ค ๊นŒ๋จน์–ด์„œ ๋ณต์Šต์šฉ ์˜ˆ์‹œ ์ฃผ์„์„ ์ถ”๊ฐ€ํ•ด๋‘ 
24+
- ํฌ์ธํ„ฐ ์กฐ์ž‘(์—ฐ๊ฒฐ๋ฆฌ์ŠคํŠธ ๋’ค์ง‘๊ธฐ, ๋ณ‘ํ•ฉ)์ด ์–ด๋ ค์›€. ์Šคํƒ ํ’€์ด๋„ ์ค€๋น„ํ•ด๋‘๊ธฐ.
2525
"""
2626
# Definition for singly-linked list.
2727
# class ListNode:
@@ -31,60 +31,38 @@
3131
class Solution:
3232
def reorderList(self, head: Optional[ListNode]) -> None:
3333
# ์ดˆ๊ธฐ ์ƒํƒœ: 1->2->3->4->5
34-
34+
"""
35+
Do not return anything, modify head in-place instead.
36+
"""
3537
# 1๋‹จ๊ณ„: ์ค‘๊ฐ„ ์ง€์  ์ฐพ๊ธฐ
36-
slow = head # slow = 1
37-
fast = head # fast = 1
38+
slow = head
39+
fast = head
40+
3841
while fast and fast.next:
39-
slow = slow.next # slow: 1->2->3
40-
fast = fast.next.next # fast: 1->3->5->None
41-
# ๊ฒฐ๊ณผ: slow๋Š” 3์— ์œ„์น˜
42-
42+
slow = slow.next
43+
fast = fast.next.next
44+
4345
# 2๋‹จ๊ณ„: ๋’ท๋ถ€๋ถ„ ๋’ค์ง‘๊ธฐ
44-
prev = None # prev = None
45-
curr = slow.next # curr = 4 (๋’ท๋ถ€๋ถ„ ์‹œ์ž‘์ )
46+
prev = None
47+
curr = slow.next
4648
slow.next = None # ๋ถ„๋ฆฌ: 1->2->3 | 4->5
47-
49+
4850
while curr:
49-
# 1ํšŒ์ „: curr=4, prev=None
50-
next_temp = curr.next # next_temp = 5
51-
curr.next = prev # 4->None
52-
prev = curr # prev = 4
53-
curr = next_temp # curr = 5
54-
# ์ƒํƒœ: 1->2->3 | 4->None, curr=5
55-
56-
# 2ํšŒ์ „: curr=5, prev=4
57-
next_temp = curr.next # next_temp = None
58-
curr.next = prev # 5->4
59-
prev = curr # prev = 5
60-
curr = next_temp # curr = None (์ข…๋ฃŒ)
61-
# ์ƒํƒœ: 1->2->3 | 5->4->None
62-
51+
next_temp = curr.next
52+
curr.next = prev
53+
prev = curr
54+
curr = next_temp
55+
6356
# 3๋‹จ๊ณ„: ์•ž๋ถ€๋ถ„๊ณผ ๋’ท๋ถ€๋ถ„ ํ•ฉ์น˜๊ธฐ
64-
first = head # first = 1->2->3
65-
second = prev # second = 5->4
66-
57+
first = head
58+
second = prev
59+
6760
while second:
68-
# 1ํšŒ์ „: first=1, second=5
69-
temp1 = first.next # temp1 = 2
70-
temp2 = second.next # temp2 = 4
71-
72-
first.next = second # 1->5
73-
second.next = temp1 # 5->2
74-
# ํ˜„์žฌ ์ƒํƒœ: 1->5->2->3, ๋‚จ์€ second = 4
75-
76-
first = temp1 # first = 2
77-
second = temp2 # second = 4
78-
79-
# 2ํšŒ์ „: first=2, second=4
80-
temp1 = first.next # temp1 = 3
81-
temp2 = second.next # temp2 = None
82-
83-
first.next = second # 2->4
84-
second.next = temp1 # 4->3
85-
# ํ˜„์žฌ ์ƒํƒœ: 1->5->2->4->3
86-
87-
first = temp1 # first = 3
88-
second = temp2 # second = None (์ข…๋ฃŒ)
89-
90-
# ์ตœ์ข… ๊ฒฐ๊ณผ: 1->5->2->4->3
61+
temp1 = first.next
62+
temp2 = second.next
63+
64+
first.next = second
65+
second.next = temp1
66+
67+
first = temp1
68+
second = temp2

0 commit comments

Comments
ย (0)