国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

LeetCode 19. Remove Nth Node From End of List

2019-11-08 03:22:28
字體:
供稿:網(wǎng)友

Given a linked list, remove the nth node from the end of list and return its head.

For example,

   Given linked list: 1->2->3->4->5, and n = 2.   After removing the second node from the end, the linked list becomes 1->2->3->5.

Note:Given n will always be valid.

answer:

class Solution {public:    ListNode* removeNthFromEnd(ListNode* head, int n) {        ListNode * PRe, * now, * post;        now = head;        pre = now;        post = now;        for(int i = 1; i <= n; i ++){            post = post->next;        }        while(post != NULL){            pre = now;            now = now->next;            post = post->next;        }        if(pre == now){            head = head->next;            return head;        }        pre->next = now->next;        return head;    }};


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 桂阳县| 赫章县| 桃江县| 宁远县| 营口市| 西乌珠穆沁旗| 沅陵县| 资中县| 分宜县| 汤阴县| 乌兰察布市| 霍山县| 鹰潭市| 姚安县| 庐江县| 达孜县| 高碑店市| 丹棱县| 海晏县| 竹溪县| 威信县| 青阳县| 安国市| 页游| 白沙| 曲松县| 建宁县| 廊坊市| 通海县| 新蔡县| 安远县| 基隆市| 老河口市| 苏尼特右旗| 长武县| 阜城县| 中卫市| 柯坪县| 庆城县| 沾益县| 苏州市|