首页 > 编程语言 > 详细

leetcode remove Nth Node from End python

时间:2015-11-21 23:58:52      阅读:542      评论:0      收藏:0      [点我收藏+]
# 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

leetcode remove Nth Node from End python

原文:http://www.cnblogs.com/allenhaozi/p/4984960.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!