[LeetCode]Remove Nth Node From End of List
来源:互联网 发布:软件测试28原则 编辑:程序博客网 时间:2024/06/07 03:29
就是找到要删除的节点的前一个节点/** * 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 sum =0; ListNode* p = head; while(p!=NULL){ ++sum; p=p->next; } if(n==0) return head; if(n==sum) return head->next; ListNode* q; q->next= head; int j= 0; //指向要去的前一个节点 while(j!=sum-n){ q = q->next; ++j; } q->next = q->next->next; 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
- 2015 ------> 你该奋斗了 !
- Android Async HTTP Clients: Volley vs Retrofit
- 使用uploadify组件上传文件
- 1025. 反转链表 (25)
- Apk安装过程分析
- [LeetCode]Remove Nth Node From End of List
- 47.不用加减乘除做加法
- 1034. 有理数四则运算(20)
- 我的产品经理求职之路——如何编写产品分析报告
- 一道面试题,找出0-99中没有插入的一个数
- HDU 5280 BestCoder Round#47 1001
- 黑马程序员——高新技术---Java基础—常用类_obiect类,Scanner类
- [LeetCode]Valid Parentheses
- android studio SSL BKS格式keystore文件加载