Last active
May 20, 2022 09:39
-
-
Save thekhairul/36b2e7cc44117d03420a1474e833c1a8 to your computer and use it in GitHub Desktop.
Leetcode 206: Reverse linked list - python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: | |
if head == None or head.next == None: | |
return head | |
curNode = head | |
prevNode = None | |
while curNode: | |
nextNode = curNode.next | |
curNode.next = prevNode | |
prevNode = curNode | |
curNode = nextNode | |
return prevNode |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment