10. Balanced Binary Tree - Jake blog - Java coding practice log (2017)" /> 10. Balanced Binary Tree - Jake blog - Java coding practice log (2017)" />

110. Balanced Binary Tree

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」

216
0 0 216

Further Reading

Post a reply

Log inYou can only comment after that.
Share this page
Back to top