[题目] Given a binary tree, return the preordertraversal of its nodes' values. Example: Input: [1,null,2,3] 1 \ 2 / 3 Output: [1,2,3] [思路] 有参考,好机智,使用堆栈压入右子树,暂时存储. 左子树遍历完成后遍历右子树. [代码] /** * Definition for a binary tree node. * public class TreeNode { *…
解法一:From top to bottom int treeHeight(TreeNode *T) { if (T == NULL) ; ; } bool isBalanced(TreeNode* root) { if (root == NULL) return true; int left_height = treeHeight(root->left); int right_height = treeHeight(root->right); ) return false; if (!isB…