simple C solution,3 ms,5 lines


  • 0
    W
    bool helper(struct TreeNode* leftNode,struct TreeNode* rightNode){
    	if(leftNode==NULL&&rightNode==NULL) return true;
    	else if(leftNode!=NULL&&rightNode!=NULL) return leftNode->val==rightNode->val&&helper(leftNode->left,rightNode->right)&&helper(leftNode->right,rightNode->left);
    	else return false;
    }
    bool isSymmetric(struct TreeNode* root) {
        if(root==NULL) return false;
        else return helper(root->left,root->right);
    }
    

Log in to reply
 

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