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 14216ab commit d82b035Copy full SHA for d82b035
reverse-linked-list/jeldo.py
@@ -0,0 +1,15 @@
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
+class Solution:
7
+ # O(n), n = len(nodes)
8
+ def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
9
+ tail = None
10
+ while head:
11
+ temp = head.next
12
+ head.next = tail
13
+ tail = head
14
+ head = temp
15
+ return tail
0 commit comments