leetcode Remove Nth Node from Linked List
来源:互联网 发布:2016剑三毒姐捏脸数据 编辑:程序博客网 时间:2024/06/05 10:40
/** * 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) { if(head == NULL){ return NULL; } ListNode* fast = head, *slow = head; for(int i = 0; i < n; ++i){ fast = fast->next; } //if we want to delete the first node of linked list if(fast == NULL){ ListNode* tmp = slow->next; delete slow; return tmp; } while(fast->next != NULL){ slow = slow->next; fast = fast->next; } ListNode* tmp = slow->next->next; ListNode* tode = slow->next; slow->next = tmp; delete tode; return head; }};
0 0
- leetcode Remove Nth Node from Linked List
- LeetCode[Linked List]: Remove Nth Node From End of List
- leetcode题解-328. Odd Even Linked List && 19. Remove Nth Node From End of List
- leetcode 19. Remove Nth Node From End of List (Linked list)
- 19. Remove Nth Node From End of List(Linked List)
- 19. Remove Nth Node From End of List leetcode list
- [Leetcode]LeetCode 19:Remove Nth Node From End of List
- Leetcode: Remove Nth Element from Sorted Linked 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
- UVA - 1395 Slim Span
- What is the name of the “-->” operator?(Stackoverflow)
- HDU - 4607 Park Visit
- vs2013 error C4996: 'fopen': This function or variable may be unsafe.
- java笔试题01
- leetcode Remove Nth Node from Linked List
- winform打包发布安装包详解
- 遍历交换两个数组的值
- Sicily 1404. Hie with the Pie
- Sicily 1403. Caterpillar
- 免App Store分发iOS应用
- 胡松华诈骗团伙的丑陋面目
- poj2080 Calendar
- 《CG Programming in Unity》笔记1-基础知识