求一棵树的最大深度 思路:广度优先搜索即可 class Solution {public: int maxDepth(TreeNode *root) { int depth = 0; if (!root) return depth; queue nodeQue; nodeQue.push(root)...
分类:
其他好文 时间:
2015-04-11 11:38:05
阅读次数:
117
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For exam...
分类:
其他好文 时间:
2015-04-11 07:49:20
阅读次数:
107
题目:
Given a binary tree
struct TreeLinkNode {
TreeLinkNode *left;
TreeLinkNode *right;
TreeLinkNode *next;
}
Populate each next pointer to point to its next right n...
分类:
其他好文 时间:
2015-04-11 00:07:02
阅读次数:
170
Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.
Calling next() will return the next smallest...
分类:
其他好文 时间:
2015-04-11 00:03:47
阅读次数:
200
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.用空间换时间的方法,先用一个数组将节点按序存放,然后建树,代码如下:/** * D...
分类:
其他好文 时间:
2015-04-10 21:51:05
阅读次数:
117
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 stil...
分类:
其他好文 时间:
2015-04-10 19:33:42
阅读次数:
102
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointe...
分类:
其他好文 时间:
2015-04-10 17:25:22
阅读次数:
110
Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3].Not...
分类:
其他好文 时间:
2015-04-10 16:56:27
阅读次数:
117
去年google code jam第一轮的B题,我没有想明白,也没有找到题解。没有办法,就去下载了大神的代码来看看。感觉差距好大,别人用十分钟不到就做出来了。题目的描述如下,我就不写翻译了,题意挺明了的。由于墙的原因,我还是把题目贴下面吧!题目内容
A tree is a connected graph with no cycles.A rooted tree is a tree in which...
分类:
其他好文 时间:
2015-04-10 15:39:41
阅读次数:
218
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree andsum =...
分类:
其他好文 时间:
2015-04-10 15:14:35
阅读次数:
125