题目:Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5...
分类:
其他好文 时间:
2015-04-05 11:50:33
阅读次数:
135
Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
For example,
Given n = 3,
You should return the following matrix:
[
[ 1, ...
分类:
其他好文 时间:
2015-04-04 18:29:57
阅读次数:
133
Convert Sorted List to Binary Search TreeGiven a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST....
分类:
其他好文 时间:
2015-04-04 15:01:48
阅读次数:
117
题目:
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
思路:从一个数组中找到中间的元素作为BST的根,然后坐边的作为左子树,右边的作为右子树,递归调用
#include
#include
#include
#include
...
分类:
其他好文 时间:
2015-04-04 12:18:29
阅读次数:
132
题目:
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
思路:和上面的思想一样,只不过注意找到链表的中间节点的方法
void Inorder(BinTree* root)
{
if(root == NULL)
...
分类:
其他好文 时间:
2015-04-04 12:17:29
阅读次数:
136
题目:
Given a set of distinct integers, S, return all possible subsets.
Note:
Elements in a subset must be in non-descending order.
The solution set must not contain duplicate subsets.
...
分类:
其他好文 时间:
2015-04-03 17:30:47
阅读次数:
107
题目:
Given a collection of integers that might contain duplicates, S, return all possible subsets.
Note:
Elements in a subset must be in non-descending order.
The solution set must not ...
分类:
其他好文 时间:
2015-04-03 17:28:54
阅读次数:
107
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is ...
分类:
其他好文 时间:
2015-04-03 13:17:49
阅读次数:
120
The little girl loves the problems on array queries very much.One day she came across a rather well-known problem: you’ve got an array of n elements (the elements of the array are indexed starting from...
分类:
其他好文 时间:
2015-04-02 16:31:33
阅读次数:
125
??
问题描述:Given an array S of n integers,are there elements a, b, c in S such that a + b + c = 0? Find all uniquetriplets in the array which gives the sum of zero.
Note:
Elements in a tri...
分类:
其他好文 时间:
2015-04-02 15:09:13
阅读次数:
96