Symmetric Tree

/*
    给一颗二叉树,问是否关于中心对称
*/
/**
 * Definition for binary tree
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    bool isTrue(TreeNode *root1,TreeNode *root2){
        if(!root1 && !root2) return true;
        else if(!root1||!root2) return false;
        return root1->val == root2->val && isTrue(root1->left,root2->right)&&isTrue(root1->right,root2->left);
    }
    bool isSymmetric(TreeNode *root) {
        if(!root) return true;
        return isTrue(root->left,root->right);
    }
};

 

posted @ 2015-03-19 23:06  SprayT  阅读(100)  评论(0编辑  收藏  举报