Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note...
分类:
其他好文 时间:
2015-02-09 14:05:14
阅读次数:
107
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical an...
分类:
其他好文 时间:
2015-02-09 14:04:39
阅读次数:
117
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-02-09 14:04:10
阅读次数:
148
Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 uni...
分类:
其他好文 时间:
2015-02-09 14:03:20
阅读次数:
85
Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1.....
分类:
其他好文 时间:
2015-02-09 14:02:41
阅读次数:
123
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only n...
分类:
其他好文 时间:
2015-02-09 14:01:23
阅读次数:
110
题意为得出二叉树的最小深度,但深度是定义为从根节点到叶子节点的最少节点数。
容易出错的地方:为空节点时,直接返回0。这是不对的,要判断其是否有兄弟节点,没有兄弟节点的时候才能返回0,即这个节点的父节点是一个叶子节点。
错解1:
class Solution {
public:
int minDepth(TreeNode *root) {
if(root==nullptr)
...
分类:
其他好文 时间:
2015-02-09 12:58:55
阅读次数:
132
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Callingnext()will return the next...
分类:
其他好文 时间:
2015-02-09 00:45:05
阅读次数:
159
欢迎转载,如有错误或疑问请留言纠正,谢谢
Search in Rotated Sorted Array II
Follow up for "Search in Rotated Sorted Array":
What if duplicates are allowed?
Would this affect the run-time complexity? How and w...
分类:
其他好文 时间:
2015-02-08 18:16:36
阅读次数:
199
欢迎转载,如有错误或疑问请留言纠正,谢谢
Sqrt(x)
Implement int sqrt(int x).
Compute and return the square root of x.
//vs2012测试代码
//using binary search to solve sqrt(x)
//alternative method: newton me...
分类:
其他好文 时间:
2015-02-08 16:55:02
阅读次数:
171