110. Balanced Binary Tree

 1 class Solution {
 2     public boolean isBalanced(TreeNode root) {
 3         if(root == null) return true;
 4         return(isBalanced(root.left) && isBalanced(root.right) && Math.abs(dfs(root.left) - dfs(root.right)) > 1);
 5         
 6     }
 7     
 8     public int dfs(TreeNode root) {
 9         if(root == null) return 0;
10         return (Math.max(dfs(root.left), dfs(root.right))+1);
11         
12     }
13 }

 

posted @ 2018-09-21 07:49  jasoncool1  阅读(77)  评论(0编辑  收藏  举报