对称的二叉树
对称的二叉树
https://www.nowcoder.com/practice/ff05d44dfdb04e1d83bdbdab320efbcb?tpId=13&tqId=11211&tPage=3&rp=1&ru=%2Fta%2Fcoding-interviews&qru=%2Fta%2Fcoding-interviews%2Fquestion-ranking
/* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } }; */ class Solution { public: bool isSame(TreeNode* pRoot1,TreeNode* pRoot2) { if(pRoot1==NULL&&pRoot2==NULL) { return true; } if(pRoot1==NULL||pRoot2==NULL) { return false; } if(pRoot1->val!=pRoot2->val) { return false; } return isSame(pRoot1->left,pRoot2->right)&&isSame(pRoot2->left,pRoot1->right); } bool isSymmetrical(TreeNode* pRoot) { return isSame(pRoot,pRoot); } };