Skip to content

Instantly share code, notes, and snippets.

@thekhairul
Last active May 20, 2022 09:39
Show Gist options
  • Save thekhairul/36b2e7cc44117d03420a1474e833c1a8 to your computer and use it in GitHub Desktop.
Save thekhairul/36b2e7cc44117d03420a1474e833c1a8 to your computer and use it in GitHub Desktop.
Leetcode 206: Reverse linked list - python
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