This problem is just similar toMinimum Depth of Binary Tree.The first solution also uses recursion (not sure whether it can be called DFS).1 class Sol...
分类:
其他好文 时间:
2015-08-15 19:52:05
阅读次数:
123
这两个问题实际上是同一个问题,需要对三种遍历方式的规律非常清楚。对于前序遍历,第一个元素实际上就是root,然后后面的元素前半部分是左树的node,后半部分是右树的node对于中序遍历,一旦我们知道了root节点,那么就可以将其分为两半部分,也就是左树和右树对于后序遍历,我们可以缺点最后一个节点是r...
分类:
其他好文 时间:
2015-08-15 19:50:05
阅读次数:
128
Well, this problem has the highest acceptance rate among all OJ problems. It has a very easy 1-line reursive solution. I am not sure whether this one ...
分类:
其他好文 时间:
2015-08-15 19:49:12
阅读次数:
131
The basic idea is to use binary search: keep two pointerslandrfor the current search range, then find the middle elementnums[mid]in this range. Ifnums...
分类:
其他好文 时间:
2015-08-15 19:44:56
阅读次数:
76
Problem Description
The reflected binary code, also known as Gray code after Frank Gray, is a binary numeral system where two successive values differ in only onebit (binary digit). The reflected b...
分类:
其他好文 时间:
2015-08-15 18:26:59
阅读次数:
127
The idea is to search for the left and right boundaries of target via two binary searches. Well, some tricks may be needed. Take a look at this link :...
分类:
其他好文 时间:
2015-08-15 18:10:48
阅读次数:
96
一、Unique Binary Search TreesI统计个数迭代的方法可以解决。f(0)=1,f(1)=1,f(2)=2,f(3)=3.f(4)=f(0)*f(3)+f(1)*f(2)+f(2)*f(1)+f(3)*f(0)=10;f(5)=f(0)*f(4)+f(1)*f(3)+f(2)*f...
分类:
其他好文 时间:
2015-08-15 18:00:17
阅读次数:
92
一、normal fasion使用queue记录上次访问的是记录的孩子节点 1 public List> levelOrder(TreeNode root) { 2 List> res = new LinkedList>(); 3 Queue queue = new LinkedLi...
分类:
其他好文 时间:
2015-08-15 17:51:51
阅读次数:
173
04-树4. Root of AVL Tree (25)时间限制100 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, YueAn AVL tree is a self-balancing binary search tree. In an AVL tre...
分类:
其他好文 时间:
2015-08-15 17:51:19
阅读次数:
125
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 nodes with keys less than the node's key.Th...
分类:
其他好文 时间:
2015-08-15 16:31:50
阅读次数:
107