总结:其实就是反转链表。不过是反转中间一部分。要注意的是保存第一个结点的前继的指针; 若第一个结点是头结点,注意反转子串的尾结点变为头结点。
分类:
其他好文 时间:
2014-08-25 01:07:43
阅读次数:
198
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After ...
分类:
其他好文 时间:
2014-08-24 19:13:32
阅读次数:
194
题目描述:
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
给定一个有序的链表,要求构建一颗平衡二叉查找树。
解析:二叉查找树的中序遍历的结构就是一颗二叉查找树,要使得最终的二叉查找树的结构尽可能的平衡,也就是说只需要...
分类:
其他好文 时间:
2014-08-23 23:02:31
阅读次数:
389
Remove Duplicates from Sorted List II
Total Accepted: 17137 Total
Submissions: 69046My Submissions
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only d...
分类:
其他好文 时间:
2014-08-23 14:00:40
阅读次数:
187
LeetCode: Copy List with Random PointerA linked list is given such that each node contains an additional random pointer which could point to any node ...
分类:
其他好文 时间:
2014-08-23 12:34:30
阅读次数:
193
LeetCode: Linked List CycleGiven a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space?地址:https://oj....
分类:
其他好文 时间:
2014-08-22 22:28:09
阅读次数:
285
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2-...
分类:
其他好文 时间:
2014-08-22 22:22:09
阅读次数:
233
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, ...
分类:
其他好文 时间:
2014-08-22 22:18:59
阅读次数:
342
/*#include
using namespace std;
*//**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
cla...
分类:
其他好文 时间:
2014-08-22 19:46:39
阅读次数:
147
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the o...
分类:
其他好文 时间:
2014-08-21 20:58:34
阅读次数:
244