Solution Function Link: ide.geeksforgeeks.org/online-cpp-compiler/b4d0bdb1-df21-44e6-b8da-6f1ccc96a1d6
@ganeshjaggineni40974 ай бұрын
NICE SUPER EXCELLENT MOTIVATED
@prateekbhaisora Жыл бұрын
I think it is too overcomplicated. A simpler code is: class Solution{ public: int height(Node *root) { if (!root) return 0; return 1 + max(height(root->left), height(root->right)); } bool isBalanced(Node *root) { if (!root) return true; int l = height(root->left); int r = height(root->right); return abs(l-r) left) && isBalanced(root->right); } // TC = O(n) SC = O(n) };