Balanced Binary Tree
2014-02-06 15:20
78 查看
public class Solution { public boolean isBalanced(TreeNode root) { if(root==null) return true; if(checkHeight(root)==-1) return false; return true; } public int checkHeight(TreeNode root){ if(root==null) return 0; int left = checkHeight(root.left); int right = checkHeight(root.right); if(right==-1||left==-1) return -1; if(Math.abs(left-right)>1) return -1; return Math.max(left,right)+1; } }
View Code
相关文章推荐
- 110. Balanced Binary Tree
- leetcode-110. Balanced Binary Tree
- Balanced Binary Tree
- leetcode Balanced Binary Tree
- Balanced Binary Tree
- LeetCode题解——Balanced Binary Tree
- leetcode -- 110. Balanced Binary Tree 【二叉树是否平衡】
- leetcode--110. Balanced Binary Tree
- Leetcode: Balanced Binary Tree
- leetcode:Balanced Binary Tree
- Balanced Binary Tree - LeetCode
- Balanced Binary Tree
- LeetCode 110:Balanced Binary Tree
- Leetcode 110 Balanced Binary Tree
- LeetCode 110:Balanced Binary Tree
- Algorithm: Binary Tree(2) -- Special Trees (BST and Balanced Tree)
- LeetCode 110 Balanced Binary Tree
- LeetCode110.Balanced Binary Tree题解
- LeetCode Online Judge 题目C# 练习 - Balanced Binary Tree
- [leetcode] Balanced Binary Tree