Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differs by more than 1.
/** * Definition for a binary tree node. * public class TreeNode { * int val; TreeNode root){ if(root == null){ return deep-1; } int l = deep(deep+1,root.left); int r = deep(deep+1,root.right); if(Math.abs(l-r) >1){ return -99; } return l>r?l:r; } } This siteOriginal articleAll follow "Attribution-NonCommercial-ShareAlike 4.0 License (CC BY-NC-SA 4.0)Please retain the following annotations when sharing or adapting:
Original author:Jake Tao,source:「110. Balanced Binary Tree」