【题目】
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}, reorder it to {1,4,2,3}.
【题意】
给定一个链表L: L0→L1→…→Ln-1→Ln,对他重新排序成L...
分类:
其他好文 时间:
2014-06-30 10:11:14
阅读次数:
158
【题目】
Given a binary tree, return the postorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [3,2,1].
Note: Recursive solution is trivial, could you do it iteratively?
【题意】
非递归实现后续遍...
分类:
其他好文 时间:
2014-06-30 10:10:10
阅读次数:
177
【题目】
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.
For example, given
s = "leetcode",
dict = ["leet", "code"].
Return true because "leetcode" can be segm...
分类:
其他好文 时间:
2014-06-30 09:02:26
阅读次数:
276
【题目】
Given a binary tree, return the preorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [1,2,3].
Note: Recursive solution is trivial, could you do it iteratively?
【题意】
非递归返回先序遍历...
分类:
其他好文 时间:
2014-06-30 06:21:18
阅读次数:
334
【题目】
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.
Return all such possible sentences.
For example, given
s = "catsanddog",
dict = ["cat", "cats", "and", "sand", "dog...
分类:
其他好文 时间:
2014-06-30 00:51:41
阅读次数:
295
【题目】
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.
Follow up:
Can you solve it without using extra space?
【题意】
给定一个单向链表,如果链表有环,则返回环开始的位置。
【思路】
仍然是维护两个指针, p1, p2, p1每次走一步, p2每次走两步
...
分类:
其他好文 时间:
2014-06-29 23:59:21
阅读次数:
354
【题目】
Given an array of integers, every element appears three times except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
【题意】
给定一个整数以外,其中除了一个整数只出现一次以外...
分类:
其他好文 时间:
2014-06-29 22:52:35
阅读次数:
246
【题目】
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
【题意】
判断一个单向链表是否有环
【思路】
维护两个指针p1和p2,p1每次向前移动一步,p2每次向前移动两步
如果p2能够追上p1,则说明链表中存在环...
分类:
其他好文 时间:
2014-06-29 22:51:33
阅读次数:
267
【题目】
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.
get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.
se...
分类:
其他好文 时间:
2014-06-29 22:45:26
阅读次数:
358
【题目】
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.
Return a deep copy of the list.
【题意】
给定一个链表,每个节点除了next指针外,还有一个random指针,指向任意的节点。
要求,复制这样的一个链表
【思路】
思路...
分类:
其他好文 时间:
2014-06-29 20:41:21
阅读次数:
232