Skip to content

Instantly share code, notes, and snippets.

@linfongi
Created August 20, 2016 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linfongi/a8e55c230a823de0c0945596505df9d5 to your computer and use it in GitHub Desktop.
Save linfongi/a8e55c230a823de0c0945596505df9d5 to your computer and use it in GitHub Desktop.
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def reverseList(self, head):
prev = None
while head:
next = head.next
head.next = prev
prev = head
head = next
return prev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment