110.Balanced Binary Tree Posted on 2017-09-13 | In LeetCode Solution 1: acceptedUse -1 as flag of inbalanced tree. Use another variable for better practice in production. 123456789101112131415161718class Solution { public boolean isBalanced(TreeNode root) { return maxDepth(root) != -1; } private int maxDepth(TreeNode root) { if (root == null) { return 0; } int left = maxDepth(root.left); int right = maxDepth(root.right); if (Math.abs(left - right) > 1 || left == -1 || right == -1) { return -1; } return Math.max(left, right) + 1; }}