1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x),
分类:
其他好文 时间:
2016-03-02 20:04:23
阅读次数:
178
Question: Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that duplicates do not exist in the tree. Ana
分类:
其他好文 时间:
2016-03-02 18:10:08
阅读次数:
153
Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, return [1,2,3]. 解题思路: 题目很简单,就是求一个二叉
分类:
其他好文 时间:
2016-03-02 17:45:10
阅读次数:
142
Question: 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 con
分类:
其他好文 时间:
2016-03-02 14:53:15
阅读次数:
127
Binary Tree Level Order Traversal 题目描述: Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by
分类:
其他好文 时间:
2016-03-02 14:48:42
阅读次数:
136
1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x),
分类:
其他好文 时间:
2016-03-01 22:45:03
阅读次数:
195
前序遍历 递归: 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x)
分类:
其他好文 时间:
2016-03-01 22:31:17
阅读次数:
183
思路:维护两个stack<TreeNode*> stk1, stk2,stk1存放当前层的节点,stk2存放下一层的节点。 bool right表示下一层的顺序,如果为True则下一层为从右到左,因为stk2是stack,所以stk2先存cur->left,然后存cur->right。 当stk1为
分类:
其他好文 时间:
2016-03-01 22:21:45
阅读次数:
192
Same Tree: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 id...
分类:
其他好文 时间:
2016-03-01 21:00:42
阅读次数:
171
Balanced Binary Tree:Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tr...
分类:
其他好文 时间:
2016-03-01 20:44:24
阅读次数:
153