leetcode之symmetric-tree(判断二叉树是否是镜像二叉树)
题目
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree is symmetric:
But the following is not:
Bonus points if you could solve it both recursively and iteratively.
confused what"{1,#,2,3}"means? > read more on how binary tree is serialized on OJ.
题意
给定一颗二叉树,判断该二叉树是否是镜像二叉树,返回结果。
解题思路
直接利用其对称性,递归判断其左子树的left是否和右子树的right相等,左子树的right是否和右子树的left相等。
C++实现代码
/*