原题地址普遍的做法是:用栈保存从根节点到当前尚未遍历过的最小节点的路径(栈顶始终是最小节点)constructor:遍历至最小节点,同时将路径上出现的节点压栈保存hasNext:返回栈里面是否还有元素next:栈顶元素即为所求,弹栈的同时更新栈,使栈里始终保存的是从根节点到剩余未遍历节点的最小节点的...
分类:
其他好文 时间:
2015-01-27 07:00:41
阅读次数:
184
Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,...
分类:
其他好文 时间:
2015-01-27 01:51:12
阅读次数:
198
Add BinaryGiven two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".Hide TagsMathString先补全字符串,从末尾开始加,每次计算...
分类:
其他好文 时间:
2015-01-27 00:30:35
阅读次数:
142
Validate Binary Search TreeGiven a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtre...
分类:
其他好文 时间:
2015-01-27 00:29:27
阅读次数:
205
Unique Binary Search TreesGivenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a to...
分类:
其他好文 时间:
2015-01-27 00:16:11
阅读次数:
218
Symmetric TreeGiven a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric...
分类:
其他好文 时间:
2015-01-27 00:14:03
阅读次数:
145
uva 575 Skew Binary
When a number is expressed in decimal, the k-th digit represents a multiple of 10k. (Digits are numbered from right to left, where the least significant digit is number 0.) ...
分类:
其他好文 时间:
2015-01-26 23:01:06
阅读次数:
373
题目:
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
我的解法:
(1)算法思想:
二分法,数组的中间点为根节点,然后递归。
(2)代码如下:
{CSDN:CODE:589537}...
分类:
其他好文 时间:
2015-01-26 19:21:31
阅读次数:
136
Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].这道...
分类:
其他好文 时间:
2015-01-26 16:41:21
阅读次数:
118
题目:
Follow up for problem "Populating Next Right Pointers in Each Node".
What if the given tree could be any binary tree? Would your previous solution still work?
Note:
You may only use co...
分类:
编程语言 时间:
2015-01-26 13:41:55
阅读次数:
253