Skip to content

Instantly share code, notes, and snippets.

@luojiyin1987
Created July 31, 2018 09:37
Show Gist options
  • Save luojiyin1987/531ca05072aa0a08b945d72099f8cc3d to your computer and use it in GitHub Desktop.
Save luojiyin1987/531ca05072aa0a08b945d72099f8cc3d to your computer and use it in GitHub Desktop.
Reverse Linked List
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def reverseList(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
dummy = ListNode(0)
while head:
next = head.next
head.next = dummy.next
dummy.next = head
head = next
return dummy.next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment