#101

LeetCode:Symmetric Tree

故事扮演 提交于 2019-11-26 22:13:44
1、题目名称 Symmetric Tree(判断二叉树是否对称) 2、题目地址 https://leetcode.com/problems/symmetric-tree/ 3、题目内容 英文:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). 中文:给定一颗二叉树,检查它是否与自己的镜像是同一棵树(即围绕根节点对称)。 4、解题方法 本题与题目“ Same Tree ”的解法类似,使用递归函数考察整棵树,包括左右对称节点的值和对称节点的两个子枝。需要注意的是比较子枝的时候,比较的位置是对称的位置,即用左树的右枝去比较右树的左枝,用左树的左枝去比较右树的右枝。 一段可以AC的Java代码如下: /** * 功能说明:LeetCode 101 - Symmetric Tree * 开发人员:Tsybius2014 * 开发时间:2015年8月13日 */ public class Solution { /** * 判断二叉树是否对称 * @param root 二叉树根节点 * @return true:对称 false:不对称 */ public boolean isSymmetric(TreeNode root) { if (root ==