We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
题目描述:
给定一个二叉树,检查它是否是镜像对称的。
例如,二叉树 [1,2,2,3,4,4,3] 是对称的。
[1,2,2,3,4,4,3]
1 / \ 2 2 / \ / \ 3 4 4 3
但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的:
[1,2,2,null,3,null,3]
1 / \ 2 2 \ \ 3 3
说明:
如果你可以运用递归和迭代两种方法解决这个问题,会很加分。
解题思路:两棵树左右对称,两个根节点的值相同,根的左子树与右子树互为镜像。看的题目下的官网解题思路。
C解题:
bool isMirro(struct TreeNode* p, struct TreeNode* q){ if(!p && !q) return true; if(!p || !q) return false; return (p->val == q->val) && isMirro(p->left,q->right) && isMirro(p->right,q->left); } bool isSymmetric(struct TreeNode* root){ return isMirro(root,root); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
题目描述:
给定一个二叉树,检查它是否是镜像对称的。
例如,二叉树
[1,2,2,3,4,4,3]
是对称的。但是下面这个
[1,2,2,null,3,null,3]
则不是镜像对称的:说明:
如果你可以运用递归和迭代两种方法解决这个问题,会很加分。
解题思路:两棵树左右对称,两个根节点的值相同,根的左子树与右子树互为镜像。看的题目下的官网解题思路。
C解题:
The text was updated successfully, but these errors were encountered: