/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public boolean isSymmetric(TreeNode root) {
if (root == null) return true;
return compare(root.left, root.right);
}
public boolean compare(TreeNode l, TreeNode r){
if (l != null && r != null){
return l.val == r.val && compare(l.left, r.right) && compare(l.right, r.left);
}
return l==r;
}
}
Symmetric Tree
最新推荐文章于 2022-04-21 23:25:34 发布