101 Symmetric Tree

题意:

判断一颗二叉树是否对称

代码:

bool comp(TreeNode* l, TreeNode* r) {
	if (l == NULL&&r == NULL)
		return true;
	if (l == NULL||r == NULL)
		return false;
	if (l->val != r->val)
		return false;
	return comp(l->left, r->right) && comp(l->right, r->left);

}

bool isSymmetric(TreeNode* root) {
	if (!root)
		return true;
	return comp(root->left, root->right);
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
05-21 00:27
点赞 评论 收藏
分享
真烦好烦真烦:牛友太有实力了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务