leetcode:Remove Nth Node From End of List
来源:互联网 发布:matlab黄金分割算法 编辑:程序博客网 时间:2024/05/16 10:08
/** * 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 *kp=head; ListNode *mp=head; ListNode *pre=mp; int step=0; while(kp->next!=NULL && step<n-1 ) { kp=kp->next; step++; } while(kp->next!=NULL) { kp=kp->next; pre=mp; mp=mp->next; } if(pre==head && pre==mp) { head=pre->next; pre->next=NULL; delete pre; } else { pre->next=mp->next; mp->next=NULL; delete mp; } return head; }};
0 0
- LeetCode[Linked List]: Remove Nth Node From End of List
- 19. Remove Nth Node From End of List leetcode list
- [Leetcode]LeetCode 19:Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List
- [Leetcode] Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List
- leetcode 40: Remove Nth Node From End of List
- [LeetCode] Remove Nth Node From End of List
- Leetcode 19 Remove Nth Node From End of List
- [Leetcode] Remove Nth Node From End of List
- [LeetCode]Remove Nth Node From End of List
- LeetCode-Remove Nth Node From End of List
- [LeetCode] Remove Nth Node From End of List
- LeetCode 19: Remove Nth Node From End of List
- LeetCode - Remove Nth Node From End of List
- LeetCode | Remove Nth Node From End of List
- leetcode之Remove Nth Node From End of List
- 面向对象、面向过程的思考
- 纯洁的友谊
- 机器学习自学入门相关推荐
- 为什么要实现Serializable
- 20140430收盘小结
- leetcode:Remove Nth Node From End of List
- 数据库查询生成器控件集Active Query Builder免费下载功能详解
- shape文件用法二:在Android中,用XML文件实现圆角的效果
- Linux系统中UI库curse.h不存在问题——贪吃蛇为例
- Android ActionBar详解
- 使用Jquery向一个空白网页动态创建一个iframe,及嵌入页面,和向嵌入页面传参
- mtd device上的JFFS2等文件系统不建议使用在block device上
- zend studio装调式工具xdebug
- LCS