Given a binary tree, flatten it to a linked list in-place.For example,
Given 1
/ 2 5
/ \ 3 4 6The flattened tree should look like: 1
2...
分类:
其他好文 时间:
2015-06-13 14:19:28
阅读次数:
86
Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).For example:
Given binary tree {3,9,20,#,#,15,7}, 3...
分类:
其他好文 时间:
2015-06-13 12:57:50
阅读次数:
98
http://bookshadow.com/weblog/2015/01/19/leetcode-binary-tree-postorder-traversal/http://bookshadow.com/weblog/2015/01/19/binary-tree-post-order-traver...
分类:
其他好文 时间:
2015-06-13 12:36:30
阅读次数:
111
Given a binary tree, return the preorder traversal of its nodes’ values.For example:
Given binary tree{1,#,2,3}, 1
2
/
3return [1,2,3].递归遍历:/**C++
* Definition for a binary tree n...
分类:
其他好文 时间:
2015-06-13 11:27:51
阅读次数:
143
LeetCode Invert Binary Tree题目思路没什么思路可言;
真不敢相信他写不出;代码struct TreeNode* invertTree(struct TreeNode* root) {
if (root == NULL) return root;
invertTree(root->left);
invertTree(root->right);...
分类:
其他好文 时间:
2015-06-13 11:27:30
阅读次数:
234
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,1].Note: Recursive solution is trivial, could...
分类:
其他好文 时间:
2015-06-13 11:23:14
阅读次数:
113
Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).For example:
Given binary tree {3,9,20,#,#,15,7}, 3
/ 9 20
/ 1...
分类:
其他好文 时间:
2015-06-13 11:20:46
阅读次数:
114
Given n, how many structurally unique BST’s (binary search trees) that store values 1…n?For example,
Given n = 3, there are a total of 5 unique BST’s. 1 3 3 2 1
\ /...
分类:
其他好文 时间:
2015-06-13 09:58:12
阅读次数:
104
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 number in the BST.Note: next() and hasN...
分类:
其他好文 时间:
2015-06-13 09:56:01
阅读次数:
100
树的遍历当初觉得难死,现在还好public class Solution { public ArrayList preorderTraversal(TreeNode root) { ArrayList res = new ArrayList(); if(root=...
分类:
其他好文 时间:
2015-06-13 07:35:26
阅读次数:
118