Skip to content

Commit 5467561

Browse files
committed
206
1 parent 8a3c435 commit 5467561

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

0001-500/Reverse Linked List.py

+15
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+
def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
8+
previous = None
9+
current = head
10+
while current:
11+
next_temp = current.next
12+
current.next = previous
13+
previous = current
14+
current = next_temp
15+
return previous

0 commit comments

Comments
 (0)