题解 | #对称的二叉树#
对称的二叉树
https://www.nowcoder.com/practice/ff05d44dfdb04e1d83bdbdab320efbcb
bool isSymmetricalTree(struct TreeNode* pRoot, struct TreeNode* pRoot2) {
if (pRoot == NULL && pRoot2 == NULL)
return true;
if (pRoot == NULL || pRoot2 == NULL)
return false;
if (pRoot->val == pRoot2->val) {
if (isSymmetricalTree(pRoot->left, pRoot2->right) &&
isSymmetricalTree(pRoot2->left, pRoot->right))
return true;
}
return false;
}
bool isSymmetrical(struct TreeNode* pRoot ) {
// write code here
if (pRoot == NULL)
return true;
return isSymmetricalTree(pRoot->left, pRoot->right);
}
