A 16ms Accepted Solution


  • 0
    Y
    class Solution {
    public:
        bool isBalanced(TreeNode* root) {
            if(!root) return true;
            if(abs(depth(root->left) - depth(root->right)) > 1) return false;
            else return (isBalanced(root->left)&isBalanced(root->right));
        }
        
        int depth(TreeNode* root) {
            if(!root) return 0;
            return max(depth(root->left), depth(root->right)) + 1;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.