首页 > 其他 > 详细

leetcode(10)-删除链表的倒数第N个节点

时间:2020-01-02 22:20:33      阅读:70      评论:0      收藏:0      [点我收藏+]

给定一个链表,删除链表的倒数第 n 个节点,并且返回链表的头结点。

链接 https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/

凑数吧

class Solution:
    def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
        lists = []
        arrow = head
        while arrow:
            lists.append(arrow)
            arrow = arrow.next
        print()
        if -n-1>=-len(lists):
            lists[-n-1].next = lists[-n].next
        else:
            return head.next
        return head

leetcode(10)-删除链表的倒数第N个节点

原文:https://www.cnblogs.com/Lzqayx/p/12142215.html

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