Created
August 20, 2016 21:58
-
-
Save linfongi/a8e55c230a823de0c0945596505df9d5 to your computer and use it in GitHub Desktop.
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
# 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