LeetCode-Remove Nth Node From End of List
来源:互联网 发布:软件开发部门职责 编辑:程序博客网 时间:2024/06/03 13:01
/** * 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 = new ListNode(0); p->next = head; ListNode *f, *s; f = s = p; while(n--) { f = f->next; } while(f->next != NULL) { f = f->next; s = s->next; } s->next = s->next->next; return p->next; }};
经过几个小时,渣渣终于把题解出来,虽然用的方法很土
主要问题出现在对链表操作不熟,没有搞清结构体指针的真正含义,导致出现bug。
这段代码严格上来说没有符合要,因为遍历了两次了,这篇博客提供的方法很好,需要多多加强http://blog.csdn.net/makuiyu/article/details/43315519
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
- hessian 入门
- UGUI下拉列表控件
- 三十而立,从零开始学ios开发(十六):Navigation Controllers and Table
- Java反射机制详解
- 表单的CSS设计
- LeetCode-Remove Nth Node From End of List
- 三十而立,从零开始学ios开发(十五):Navigation Controllers and Table
- 常用的android弹出对话框
- opencv如何获取摄像头的数量
- 三十而立,从零开始学ios开发(十四):Navigation Controllers and Table Views(上) - minglz - 博客园
- 最简单的基于FFmpeg的移动端例子附件:IOS自带播放器
- Overflow
- 三十而立,从零开始学ios开发(十三):Table Views(下)Grouped and I
- Connections between cities