We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 56bc4a3 + ebad1f4 commit 047fc5cCopy full SHA for 047fc5c
1 file changed
leetcode3/변지협/206. Reverse Linked List.py
@@ -0,0 +1,42 @@
1
+'''
2
+1. 아이디어 :
3
+2. 시간복잡도 :
4
+ O(n)
5
+3. 자료구조/알고리즘 :
6
7
+
8
+# Definition for singly-linked list.
9
+# class ListNode:
10
+# def __init__(self, val=0, next=None):
11
+# self.val = val
12
+# self.next = next
13
+class Solution:
14
+ def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
15
+ """
16
+ :type head: Optional[ListNode]
17
+ :rtype: Optional[ListNode]
18
19
+ if head == None:
20
+ return None
21
+ temp = []
22
+ _next = head
23
+ while True:
24
+ val = _next.val
25
+ _next = _next.next
26
27
+ temp.append(val)
28
29
+ if _next is None:
30
+ break
31
32
+ # temp = temp[::-1]
33
+ prev = None
34
+ for i in range(len(temp)):
35
+ # if prev is not None:
36
+ # print(prev.val)
37
+ prev = ListNode(val=temp[i], next=prev)
38
39
+ print(prev.next, prev.val)
40
41
+ return prev
42
0 commit comments