Remove Nth Node From End of List
来源:互联网 发布:情迷彼得堡 知乎 编辑:程序博客网 时间:2024/05/04 04:31
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *removeNthFromEnd(ListNode *head, int n) { if(head == NULL){ return NULL; } ListNode *phead = new ListNode(0); phead->next = head; ListNode *back = phead, *front = phead; while(n--){ front = front->next; } while(front->next != NULL){ front = front->next; back = back->next; } ListNode *p = back->next; back->next = p->next; delete p; return phead->next; }};
0 0
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node from End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- 嵌入式linux串口编程(下)
- acm 乘法逆元 或线段树 UVALive 5798
- Android 高仿微信实时聊天 基于百度云推送
- 我的大一暑假——2014"TI"杯全国大学生电子竞赛总结(一)
- N-Queens
- Remove Nth Node From End of List
- Android核心基础——S02E01_短信发送器
- 正则表达式
- 机房重构 之 抽象工厂+反射+配置文件 实现数据库访问
- hdu 1003 Max Sum 简单动态规划
- 100层楼,2个玻璃杯
- CSS the Definitive Guide
- 花生壳免费域名怎么用
- MAC OS搭建Apache服务器PHP环境及MySQL数据库