剑指offer--对称二叉树

/*
struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
    TreeNode(int x) :
            val(x), left(NULL), right(NULL) {
    }
};
*/
class Solution 
{
public:
    bool panduan(TreeNode* left, TreeNode* right)
    {
        if (left == NULL&&right == NULL) return true;
        if (left == NULL || right == NULL)    return false;
        if (left->val == right->val)
        {
            return (panduan(left->left, right->right) && panduan(left->right, right->left)); 
        }
        return false;
    }
    bool isSymmetrical(TreeNode* pRoot)
    {
        if (pRoot == NULL) return true;
        else
        {
            return panduan(pRoot->left, pRoot->right);
        }
    }

};

 

posted @ 2017-08-02 02:02  双马尾是老公的方向盘  阅读(113)  评论(0编辑  收藏  举报