Leetcode:表面28.対称バイナリツリーの質問

Leetcode:表面28.対称バイナリツリーの質問

Leetcode:表面28.対称バイナリツリーの質問

口で言うだけなら簡単です 。私のコードを表示します。

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    bool isS(TreeNode* left,TreeNode* right){
        if(left==NULL&&right==NULL) return true;
        if(left==NULL||right==NULL) return false;
        if(left->val==right->val) return isS(left->left,right->right)&&isS(left->right,right->left);
        return false;
    }
    bool isSymmetric(TreeNode* root) {
        if(root==NULL) return true;
        return isS(root->left,root->right);
    }
};

おすすめ

転載: www.cnblogs.com/cell-coder/p/12381550.html