Remove Nth Node From End of List
来源:互联网 发布:油蜡皮沙发价格知乎 编辑:程序博客网 时间:2024/04/26 10:23
/** * 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) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. if (!head) return NULL; ListNode *cur=head, *pre=NULL; int len=0; while (cur) { len++; cur = cur->next; } if (len<n || n==0) { return head; } int i=0; ListNode *res = new ListNode(0); res->next = head; pre = res; cur=pre->next; while(i<len-n){ pre=cur; cur=cur->next; i++; } pre->next = cur->next; return res->next; }};
- 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
- mongodb集成spring
- mongodb分布式集群架构
- python 获取当前脚本所在路径
- VC++操作word
- poj2407 Relatives 欧拉函数基本应用
- Remove Nth Node From End of List
- Polygon获取中心点坐标
- 【C++】容器list的用法
- 3D圆环的射线拾取算法
- SpringMVC+Mybatis 基于maven archetype 模板项目搭建
- JasperReport学习时的demo
- 大话数据结构--串string
- DirectX 绘制
- VC中进行Office编程