Skip to content

Commit c0ace33

Browse files
committed
Update Readme
1 parent 42b2232 commit c0ace33

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class ListNode:
2+
def __init__(self, val=0, next=None):
3+
self.val = val
4+
self.next = next
5+
6+
7+
def reverse_list(self, head: ListNode) -> ListNode:
8+
if head is None or head.next is None:
9+
return head
10+
11+
stopped: bool = False
12+
prev = head.next
13+
head.next = None
14+
while not stopped:
15+
tmp: ListNode = prev.next
16+
prev.next = head
17+
head = prev
18+
if tmp is not None:
19+
prev = tmp
20+
else:
21+
stopped = True
22+
23+
return prev

0 commit comments

Comments
 (0)