Remove Nth Node From End of List
2015-06-04 14:57
399 查看
/** * 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) { ListNode* newHead= new ListNode(-1); newHead->next=head; ListNode* first=newHead; ListNode* second=head; while(--n) second=second->next; while(second->next!=NULL) { first=first->next; second=second->next; } first->next=first->next->next; return newHead->next; } };
相关文章推荐
- ubuntu下载并安装phantomjs和nodejs
- Cloudera Manager5配置管理之配置Namenode 的HA
- node.js 简介
- [浅学] 1、Node.js尝试_安装&运行第一个helloworld
- NameNode工作机制和DataNode副本工作机制
- Hadoop之——执行start-all.sh时namenode没有启动
- nodejs npm命令行总结
- ubuntu 下 pm2 error /usr/bin/env: node: No such file or directory解决方案
- esp8266 wifi模块刷nodemcu固件并蓝牙串口调试
- leetcode#19 Remove Nth Node From End of List
- 【leetcode】【单链表】【25】Reverse Nodes in k-Group
- 【leetcode】【单链表】【25】Reverse Nodes in k-Group
- hadoop SecondaryNameNode和NameNode
- Node.js模块 require和 exports
- Hadoop 生产环境集群平滑下线节点(datanode/tasktracker or nodemanager)
- Devstack single node Installation on VM
- Nodejs学习笔记(四)与MySQL交互(felixge/node-mysql)
- vultr vs digitalocean vs linode
- NodeJS npm常用命令
- Neo4j: Create multiple relationships between the same two nodes