Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and al...
分类:
其他好文 时间:
2015-07-28 12:19:05
阅读次数:
120
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.
For example,
Given n = 3, your program should return all 5 unique BST's shown below.
1 3...
分类:
其他好文 时间:
2015-07-28 10:52:02
阅读次数:
199
Given a binary tree, return the inorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [1,3,2].
Note: Recursive solutio...
分类:
其他好文 时间:
2015-07-28 10:51:19
阅读次数:
108
Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For exa...
分类:
其他好文 时间:
2015-07-28 00:25:01
阅读次数:
112
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
题目解析:
已知一个单链表,其中元素都是升序排列的,现在将链表转成平衡二叉树。
方法一:
我们用一个数组存储链表中元素,这样就可以利用下标访问元素,之后根据二分查找法找树的...
分类:
其他好文 时间:
2015-07-27 23:05:19
阅读次数:
141
Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,2...
分类:
其他好文 时间:
2015-07-27 22:36:15
阅读次数:
121
Binary Tree? CLRS We define binary trees recursively. A binary tree T is a structure defined on a finite set of nodes that either contains no nodes, o...
分类:
其他好文 时间:
2015-07-27 20:51:58
阅读次数:
209
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matrix:1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0
Return ...
分类:
其他好文 时间:
2015-07-27 19:12:53
阅读次数:
106
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.
According to the
definition of LCA on Wikipedia: “The lowest common ancestor is defined betwee...
分类:
其他好文 时间:
2015-07-27 18:48:41
阅读次数:
80
Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].No...
分类:
其他好文 时间:
2015-07-27 18:35:11
阅读次数:
98