diff --git a/solution/0100-0199/0110.Balanced Binary Tree/Solution.cpp b/solution/0100-0199/0110.Balanced Binary Tree/Solution.cpp new file mode 100644 index 0000000000000..0578b11f2c22f --- /dev/null +++ b/solution/0100-0199/0110.Balanced Binary Tree/Solution.cpp @@ -0,0 +1,14 @@ +class Solution { +public: + bool isBalanced(TreeNode* root) { + if (!root) return true; + if (abs(getDepth(root->left) - getDepth(root->right)) > 1) return false; + return isBalanced(root->left) && isBalanced(root->right); + } + +private: + int getDepth(TreeNode *root) { + if (!root) return 0; + return 1 + max(getDepth(root->left), getDepth(root->right)); + } +}; \ No newline at end of file