Update reverse_linked_list_II.py

This commit is contained in:
marina 2023-08-07 15:51:00 -07:00 committed by GitHub
parent b16196e810
commit 60b5ec4a88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,10 +18,10 @@ def reverse_list(head: Optional[Node]) -> Optional[Node]:
curr = head
while curr:
next_temp = curr.next // save the pointer for the next node so we can continue the loop
curr.next = prev // revert the list
prev = curr // save for the next node revert
curr = next_temp // receive the pointer for the next node so we can continue the loop
next_temp = curr.next
curr.next = prev
prev = curr
curr = next_temp
return prev