leetcode Remove Nth Node From End of List
来源:互联网 发布:windows 8.1工业版 编辑:程序博客网 时间:2024/05/17 20:34
只遍历一遍的做法。
/** * 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 *p=head,*before,*del; for(int i=0;i<n;i++) { p=p->next; } if(!p) return head->next; p=p->next; del=head->next; if(!p) { head->next=del->next; return head; } before=head; while(p) { before=before->next; del=del->next; p=p->next; } before->next=del->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
- 一路向北
- 【转载】PCB注意事项
- Linux进程间通信(六)---信号量通信之semget()、semctl()、semop()及其基础实验
- Android API Guides 之 App Resources(12) - Resource Types - String
- 移植uC/OS-II到STM32F103C8T6上(参考了野火的移植手册)
- leetcode Remove Nth Node From End of List
- 程序员面试题精选100题(62)
- 帮助子女成功的十大路径
- Android API Guides 之 App Resources(13) - Resource Types - Style
- 提高孩子睡眠质量 学业事半功倍
- 程序员面试题精选100题(61)-数对之差的最大值[算法]
- Do it now
- Ubuntu Code::Blocks 修改用户自定义颜色主题
- Android API Guides 之 App Resources(14) - Resource Types - More Type