leetcode 19: Remove Nth Node From End of List
2015-07-03 11:57
666 查看
/** * 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) { int len=0; ListNode *p=head; if(!p) return head; while(p) { len++; p=p->next; } n=len-n; if(n==0) head=head->next; else { p=head; for(int i=1;i!=n;i++) p=p->next; p->next=p->next->next; } return head; } };
相关文章推荐
- node.js调用C++开发的模块实例
- Nodejs 入门1 windows下安装nodejs、npm、ant及常用命令
- nodejs爬虫抓取数据之编码问题
- nodejs爬虫抓取数据乱码问题总结
- Node.js 学习笔记
- nodejs爬虫抓取数据乱码问题总结
- nodejs爬虫抓取数据之编码问题
- node.js调用C++开发的模块实例
- node.js中格式化数字增加千位符的几种方法
- nodejs 修改默认的目录
- ENode框架初始化
- mapreduce.shuffle set in yarn.nodemanager.aux-services is invalid
- Websphere中Node(节点) Profile(概要文件)和Server(应用程序服务器实例)的区别
- CCLayer 与 CCParallaxNode 结合实现视差滚动界面应注意的地方
- 子结点childNodes
- leetcode Swap Nodes in Pairs 链表
- 父节点parentNode
- 边走边学Nodejs (基础入门篇)
- node.js学习笔记之常用模块介绍
- #leetcode#Count Complete Tree Nodes