40 lines
879 B
Java
40 lines
879 B
Java
/*
|
|
* @lc app=leetcode id=101 lang=java
|
|
*
|
|
* [101] Symmetric Tree
|
|
*/
|
|
|
|
// @lc code=start
|
|
/**
|
|
* Definition for a binary tree node.
|
|
* public class TreeNode {
|
|
* int val;
|
|
* TreeNode left;
|
|
* TreeNode right;
|
|
* TreeNode() {}
|
|
* TreeNode(int val) { this.val = val; }
|
|
* TreeNode(int val, TreeNode left, TreeNode right) {
|
|
* this.val = val;
|
|
* this.left = left;
|
|
* this.right = right;
|
|
* }
|
|
* }
|
|
*/
|
|
class Solution {
|
|
public boolean isSymmetric(TreeNode root) {
|
|
return root == null ? true: isMirror(root.left, root.right);
|
|
}
|
|
|
|
private boolean isMirror(TreeNode l, TreeNode r) {
|
|
if(l == null || r == null) {
|
|
return l == r;
|
|
}
|
|
if(l.val != r.val) {
|
|
return false;
|
|
}
|
|
return isMirror(l.left, r.right) &&isMirror(l.right, r.left);
|
|
}
|
|
}
|
|
// @lc code=end
|
|
|