simple C solution,6ms

  • 0
    int helper(struct TreeNode* root, int *flag) {
        if(root==NULL) return 0;
        int leftLen=helper(root->left,flag);
        int rightLen=helper(root->right,flag);
        if(abs(leftLen-rightLen)>1) *flag=0;
        return leftLen>rightLen?leftLen+1:rightLen+1;
    bool isBalanced(struct TreeNode* root) {
    	int flag=1;
    	int deep=helper(root,&flag);
        return flag;

Log in to reply

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