0
点赞
收藏
分享

微信扫一扫

删除链表的倒数第 N 个结点

朱悟能_9ad4 2022-02-25 阅读 69

请添加图片描述

// 递归写法
class Solution {
public:
    int cur = 0;
    ListNode* removeNthFromEnd(ListNode* head, int n) {
    if(!head) return NULL;
    head -> next = removeNthFromEnd(head->next,n);
    cur++;
    if(n == cur)
        return  head->next;
    return head;
    }
};

举报

相关推荐

0 条评论