首页 > 其他 > 详细

leetcode 19 Remove Nth Node From End of List

时间:2017-02-10 23:27:19      阅读:296      评论:0      收藏:0      [点我收藏+]
class Solution {
public:
    ListNode* removeNthFromEnd(ListNode* head, int n) {
        if (!head->next) return NULL;
        ListNode *pre = head, *cur = head;
        for (int i = 0; i < n; ++i) cur = cur->next;
        if (!cur) return head->next;
        while (cur->next) {
            cur = cur->next;
            pre = pre->next;
        }
        pre->next = pre->next->next;
        return head;
    }
};

leetcode 19 Remove Nth Node From End of List

原文:http://www.cnblogs.com/wangkun1993/p/6388135.html

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