<19>——Remove Nth Node From End of List
来源:互联网 发布:东华软件薛向东 编辑:程序博客网 时间:2024/06/05 13:25
19、Remove Nth Node From End of List
删除链表中倒数第n个节点
给定一个链表,删除链表中倒数第n个节点,返回链表的头节点。
注意事项
链表中的节点个数大于等于n
给出链表1->2->3->4->5->null和 n = 2.
删除倒数第二个节点之后,这个链表将变成1->2->3->5->null.
代码:
class Solution {public: ListNode* removeNthFromEnd(ListNode* head, int n) { bool FF=false; return removeNthFromEnd(head,n,FF); } ListNode* removeNthFromEnd(ListNode* head,int &n,bool &FF) { if(head->next) //递归到最底部 head->next=removeNthFromEnd(head->next,n,FF); if(FF!=true&&--n==0)//判断是否是要删除点 { FF=true; ListNode *curr=head->next; delete head; return curr; } return head; }};
阅读全文
0 0
- <19>——Remove Nth Node From End of List
- LeetCode——Remove Nth Node From End of List
- LeetCode19——Remove Nth Node From End of List
- Remove Nth Node From End of List —— Leetcode
- Algorithms—19.Remove Nth Node From End of List
- leetcode—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
- unity粒子系统简单常用功能介绍
- 字符串插入字符串函数
- MyISAM 和InnoDB
- 函数中的this指向,以及 修改this指向的 call/apply/bind方法
- 自定义input[type=”file”]的样式
- <19>——Remove Nth Node From End of List
- windows python paramiko
- JSP-基础2
- OpenStack与Kubernetes融合架构下的优化实践
- mysql函数
- JVM调优:选择合适的GC collector
- 【algorithm】排序算法
- js小技巧
- 这段时间一直在看马士兵老师的视频,收藏这篇关于学习java的文章