Remove Nth Node From End of List
来源:互联网 发布:大数据分析是什么专业 编辑:程序博客网 时间:2024/06/06 15:38
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.
Try to do this in one pass.
ListNode *removeNthFromEnd(ListNode *head, int n) { ListNode *p1,*p2; int i=0; if(head->next==NULL) return NULL; for(p1=head,p2=head;p1->next!=NULL;i++,p1=p1->next){ if(i>=n) p2=p2->next; } if(i<n) head=p2->next; else p2->next=p2->next->next; return head;}
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
- PHP高效率写法(详解原因)
- centos安装mongodb
- I2C详细介绍
- 数据传输背后机制:ValueStack(值栈)
- Object-c note 2: 知识点小结 (Knowledge point)
- Remove Nth Node From End of List
- opencv 边缘羽化,边缘过渡
- 使用HttpClient发送HTTPS请求以及配置Tomcat支持SSL
- ASP.NET MVC4添加区域视图 找到多个与名为“home”的控制器匹配的类型
- FFMPEG中最关键的结构体之间的关系
- iOS工作记录7 :ios控件加载图片,plist,懒加载,序列帧动画,添加动画效果(实用例子)
- jQuery判断是否存在滚动条
- 分析devexpress sheduler 绘制过程(4)--如何生成view
- 软件定义的高性能计算环境构建新一代 HPC 服务平台