File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 1+ '''
2+ ์๊ฐ ๋ณต์ก๋: O(n)
3+ - ๋ฆฌ์คํธ์ ๋ชจ๋ ๋
ธ๋๋ฅผ ํ ๋ฒ์ฉ ๋ฐฉ๋ฌธํ๋ฏ๋ก ์๊ฐ ๋ณต์ก๋๋ O(n)์
๋๋ค.
4+
5+ ๊ณต๊ฐ ๋ณต์ก๋: O(n)
6+ - ์ฌ๊ท ํธ์ถ์ ์ฌ์ฉํ๋ฏ๋ก ํธ์ถ ์คํ์ ์ต๋ n๋ฒ์ ํจ์ ํธ์ถ์ด ์์ด๋ฏ๋ก ๊ณต๊ฐ ๋ณต์ก๋๋ O(n)์
๋๋ค.
7+ '''
8+ from typing import Optional
9+
10+ class ListNode :
11+ def __init__ (self , val = 0 , next = None ):
12+ self .val = val
13+ self .next = next
14+
15+ class Solution :
16+ def reverseList (self , head : Optional [ListNode ]) -> Optional [ListNode ]:
17+ if not head or not head .next :
18+ return head
19+
20+ new_head = self .reverseList (head .next ) # find the last node
21+ head .next .next = head # reverse
22+ head .next = None # remove cycle
23+
24+ return new_head
You canโt perform that action at this time.
0 commit comments