leetcode remove Nth Node from End python

# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution(object):
    def removeNthFromEnd(self, head, n):
        """
        :type head: ListNode
        :type n: int
        :rtype: ListNode
        """
        dummy=ListNode(0)
        dummy.next=head
        
        p1=p2=dummy
        
        for i in range(n):
            p1=p1.next
        while p1.next:
            p1=p1.next
            p2=p2.next
        p2.next=p2.next.next
            
        return dummy.next

@link http://www.cnblogs.com/zuoyuan/p/3701971.html

原文地址:https://www.cnblogs.com/allenhaozi/p/4984960.html