#110.Balanced Binary Tree [LeetCode Grind 75 in Java]
Kallol Bairagi
1 min read
class Solution {
public boolean ans = true;
public int checkHeightDiff(TreeNode node){
if(node == null) return 0;
int leftht = checkHeightDiff(node.left);
int rightht = checkHeightDiff(node.right);
if(Math.abs(leftht - rightht) > 1) ans = false;
return Math.max(leftht , rightht) + 1;
}
public boolean isBalanced(TreeNode root) {
checkHeightDiff(root);
return ans;
}
}
0
Subscribe to my newsletter
Read articles from Kallol Bairagi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by