110. Balanced Binary Tree(1)
来源:互联网 发布:怎么发淘宝优惠券赚钱 编辑:程序博客网 时间:2024/06/03 11:19
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: int getheight(TreeNode* root) { if(!root) return 0; if(!root->left&&!root->right) return 1; return max(getheight(root->left),getheight(root->right))+1; } bool isBalanced(TreeNode* root) { if(!root) return true; if(!root->left&&!root->right) return true; int l=getheight(root->left); int r=getheight(root->right); if(abs(l-r)>1) return false; if(isBalanced(root->left)&&isBalanced(root->right)) return true; return false; }};
0 0
- 110. Balanced Binary Tree(1)
- 110.Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 架构的本质
- 108. Convert Sorted Array to Binary Search Tree
- 110. Balanced Binary Tree
- JS第十二天
- android 遇到的一个小问题
- 110. Balanced Binary Tree(1)
- 112. Path Sum
- 程序包com.sun.image.codec.jpeg不存在 问题的完美解决
- 116. Populating Next Right Pointers in Each Node
- 119. Pascal's Triangle II
- 136. Single Number
- hdu1520(树形dp入门)
- 浅谈STM32高级定时器TIM1的OSSR和OSSI、OISX,OISXN的作用和区别
- 关于S3C2440开发板Nand flash程序烧写和运行的一些理解