quick sort of array and linked list
分类:
其他好文 时间:
2014-06-03 08:16:22
阅读次数:
359
【题目】
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, return 1->2->3.
【题意】
给定一个已排序的链表,删除其中的重复元素
【思路】
维护两个指针prev和cur, cur指针负责扫描链表,prev指向cur的前一...
分类:
其他好文 时间:
2014-06-03 04:05:39
阅读次数:
231
Given a singly linked list
L: L0→L1→…→Ln-1→Ln,
reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…
You must do this in-place without altering the nodes' values.
For example,
Given {1,2,3,4}, r...
分类:
其他好文 时间:
2014-06-03 03:12:46
阅读次数:
222
【题目】
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 original relative order of the nodes in each of the two partitions.
For example,
Given 1->4->3-...
分类:
其他好文 时间:
2014-06-03 00:02:29
阅读次数:
270
递归一下
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
Li...
分类:
其他好文 时间:
2014-06-01 17:35:40
阅读次数:
406
You are given two linked lists representing two
non-negative numbers. The digits are stored in reverse order and each of their
nodes contain a single ...
分类:
其他好文 时间:
2014-06-01 17:05:44
阅读次数:
296
【题目】
Reverse a linked list from position m to n. Do it in-place and in one-pass.
For example:
Given 1->2->3->4->5->NULL, m = 2 and n = 4,
return 1->4->3->2->5->NULL.
Note:
Given m, n satisfy the following condition:
1 ≤ m ≤ n ≤ length of list.
【题意】
...
分类:
其他好文 时间:
2014-06-01 15:08:34
阅读次数:
237
Given a linked list, swap every two adjacent nodes and return its head.
For example,
Given 1->2->3->4, you should return the list as 2->1->4->3.
Your algorithm should use only constant space....
分类:
其他好文 时间:
2014-06-01 10:41:23
阅读次数:
242
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.
If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is...
分类:
其他好文 时间:
2014-06-01 09:05:42
阅读次数:
271
【题目】
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->3->3->4->4->5, return 1->2->5.
Given 1->1->1->2->3, return 2->3.
【题意】
给定一个有序链表,删出其中重复出现的值...
分类:
其他好文 时间:
2014-05-31 21:14:11
阅读次数:
333