## LeetCode：Symmetric Tree - 判断二叉树是否对称 原

北风其凉

1、题目名称

Symmetric Tree（判断二叉树是否对称）

2、题目地址

https://leetcode.com/problems/symmetric-tree/

3、题目内容

4、解题方法

``````/**
* 功能说明：LeetCode 101 - Symmetric Tree
* 开发人员：Tsybius2014
* 开发时间：2015年8月13日
*/
public class Solution {

/**
* 判断二叉树是否对称
* @param root 二叉树根节点
* @return true：对称 false：不对称
*/
public boolean isSymmetric(TreeNode root) {
if (root == null) {
return true;
}
return isMirror(root.left, root.right);
}

/**
* 判断一颗二叉树的左右两子节点是否对称
* @param leftNode 左子节点
* @param rightNode 右子节点
* @return true：对称 false：不对称
*/
public boolean isMirror(TreeNode leftNode, TreeNode rightNode) {
if (leftNode == null && rightNode == null) {
return true;
} else if (
(leftNode != null && rightNode == null) ||
(leftNode == null && rightNode != null) ||
leftNode.val != rightNode.val ||
!isMirror(leftNode.left, rightNode.right) ||
!isMirror(leftNode.right, rightNode.left)) {
return false;
} else {
return true;
}
}
}``````

END

### 北风其凉

[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: 1/ 2 2/ / 3 4 4 3 But the following is......

2017/12/11
0
0
LeetCode 101. Symmetric Tree (对称树)

dby_freedom
2018/12/03
0
0
[LeetCode] Symmetric Tree

1、题目名称 Symmetric Tree https://leetcode.com/problems/symmetric-tree/ 2、题目内容 Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center......

2016/04/08
45
1
101. 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: 1 / 2 2 / / 3 4 4 3 But the following ......

2018/06/26
0
0
Leetcode 二叉树解题报告

1. Binary Tree Preorder Traversal Description Given a binary tree, return the preorder traversal of its nodes' values. Example: Input: [1,null,2,3] 1 2 / 3 Output: [1,2,3] Analy......

BookThief
2018/07/29
0
0

Java架构师ya七
39分钟前
6
0

vivo互联网技术

6
0

11
0
JS基础-该如何理解原型、原型链？

JS的原型、原型链一直是比较难理解的内容，不少初学者甚至有一定经验的老鸟都不一定能完全说清楚，更多的"很可能"是一知半解，而这部分内容又是JS的核心内容，想要技术进阶的话肯定不能对这个...

OBKoro1

10
0

17
0