题解 | #删除链表的倒数第n个节点#

删除链表的倒数第n个节点

http://www.nowcoder.com/practice/f95dcdafbde44b22a6d741baf71653f6

# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

#
# 
# @param head ListNode类 
# @param n int整型 
# @return ListNode类
#
class Solution:
    def removeNthFromEnd(self , head , n ):
        # write code here
        L, node = 0, head
        while node:
            L += 1
            node = node.next
        dummy = ListNode(None)
        dummy.next = head
        cur = dummy
        for i in range(L-n):
            cur = cur.next
        cur.next = cur.next.next
        return dummy.next
全部评论

相关推荐

过往烟沉:我说什么来着,java就业面就是广!
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务