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 16e6492 commit bb61497Copy full SHA for bb61497
reverse-linked-list/jinah92.py
@@ -0,0 +1,14 @@
1
+# 복잡도
2
+# 시간 복잡도: 링크드 리스트의 길이 N만큼 순회하는데 O(N)을, 다음 링크드 리스트를 검색하는 데 O(1)을 소요하므로 O(N)*O(1) = O(N)
3
+# 공간 복잡도: 리턴할 dummy의 길이 N만큼을 사용하므로 O(N)
4
+class Solution:
5
+ def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
6
+ dummy = None # reversed linked list를 저장할 변수
7
+
8
+ while head: # 노드 끝까지 순회
9
+ current = head # 현재 노드의 복사본
10
+ head = head.next # 다음 노드로 이동
11
+ current.next = dummy # 복사본의 next의 방향을 역전
12
+ dummy = current # 현재노드를 dummy head으로 변경
13
14
+ return dummy
0 commit comments