classSolution { public: intDepth(TreeNode *root){ if(!root) return0; return1+max( Depth(root->left), Depth(root->right)); } boolisBalanced(TreeNode* root){ if(!root) returntrue; // determine the height of the children int left = Depth(root->left); int right = Depth(root->right); if(abs(right-left)>1) returnfalse; elsereturnisBalanced(root->left) && isBalanced(root->right); } };