Recover Binary Search TreeTwo elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A sol...
分类:
其他好文 时间:
2015-02-06 14:38:31
阅读次数:
133
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-06 14:28:49
阅读次数:
76
游戏里经常用的概率算法,比如随机一个数,看它落在哪段。
这里涉及到随机数之后,看如何查找落在哪个段,可以用二分查找来优化:
#include
using namespace std;
int binary_search_nearest(int* arr, int begin, int end, int val){
if (!arr){
return -1;
}
int mi...
分类:
其他好文 时间:
2015-02-06 13:18:06
阅读次数:
149
Given a binary tree, return the postorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [3,2,1].
解题思路:后序遍历的过程是首先左-右-父,首先...
分类:
其他好文 时间:
2015-02-06 13:15:22
阅读次数:
109
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].
解题思路:简单的中序非递归遍历,用栈实现;
#i...
分类:
其他好文 时间:
2015-02-06 13:12:19
阅读次数:
107
Given a binary tree, return the preorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [1,2,3].
解题思路:先序遍历较为简单,直接按顺序存栈即可....
分类:
其他好文 时间:
2015-02-06 13:12:15
阅读次数:
121
1018. Binary Apple Tree
Time limit: 1.0 second
Memory limit: 64 MB
Let's imagine how apple tree looks in binary computer world. You're right, it looks just like a binary tree, i.e. any biparous b...
分类:
移动开发 时间:
2015-02-06 09:36:29
阅读次数:
231
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.Fo...
分类:
其他好文 时间:
2015-02-05 23:15:41
阅读次数:
191
1018. Binary Apple TreeTime limit: 1.0 secondMemory limit: 64 MBLet's imagine how apple tree looks in binary computer world. You're right, it looks ju...
分类:
移动开发 时间:
2015-02-05 23:14:29
阅读次数:
275
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/43532817
Given a binary tree
struct TreeLinkNode {
TreeLinkNode *left;
TreeLinkNode *right;...
分类:
其他好文 时间:
2015-02-05 22:01:19
阅读次数:
233