Skip to content

Commit d82b035

Browse files
committed
206
1 parent 14216ab commit d82b035

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

reverse-linked-list/jeldo.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)