0ms C language Solution


  • 4
    N
    /**
     * Definition for a binary tree node.
     * struct TreeNode {
     *     int val;
     *     struct TreeNode *left;
     *     struct TreeNode *right;
     * };
     */
    
    bool checkNodes(struct TreeNode* a, struct TreeNode* b)
    {
        if(a == NULL && b == NULL)
        {
            return true;
        }
        
        if(a == NULL || b == NULL)
        {
            return false;
        }
        if(a->val != b->val)
        {
            return false;
        }
        return checkNodes(a->left, b->right) && checkNodes(a->right, b->left);
    }
    bool isSymmetric(struct TreeNode* root) {
        if(root == NULL)
        {
            return true;
        }
        return checkNodes(root->left, root->right);
    }

  • 0
    R

    It's not 0ms. Your solution is not the best.


Log in to reply
 

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