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 86ffc36 commit 374df90Copy full SHA for 374df90
1 file changed
reverse-linked-list/daiyongg-kim.py
@@ -0,0 +1,20 @@
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
+
7
+class Solution:
8
+ def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
9
+ curr = head
10
+ prev = None
11
12
+ # Time Complexity : O(n)
13
+ # Space Complexity : O(1)
14
+ while curr:
15
+ temp = curr.next
16
+ curr.next = prev
17
+ prev = curr
18
+ curr = temp
19
20
+ return prev
0 commit comments