ds-algo-study
Version:
Just experimenting with publishing a package
12 lines (9 loc) • 380 B
JavaScript
// View the full problem and run the test cases at:
// https://leetcode.com/problems/balanced-binary-tree/
const { getHeight } = require("./getHeight");
function isBalanced(root) {
if (!root) return true;
let heightDifference =
Math.abs(getHeight(root.left) - getHeight(root.right)) <= 1;
return heightDifference && isBalanced(root.left) && isBalanced(root.right);
}