【leetcode❤python】206. Reverse Linked List

# 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):
        if(head==None):return None
        if(head.next==None):return head
       
        # pre=head
        # p=head.next
        # pre.next=None
        # nxt=None
        new_head=None
        while head:
            p=head
            head=head.next
            p.next=new_head
            new_head=p
        return new_head

posted @ 2016-10-12 16:57  火金队长  阅读(176)  评论(0)    收藏  举报