public class Solution {
public boolean isSymmetric(TreeNode root) {
if (root == null) return true;
return helper(root.left, root.right);
}
public static boolean helper(TreeNode l, TreeNode r) {
if (l == null && r == null) return true;
if (l == null || r == null) return false;
return (l.val == r.val) && helper(l.left, r.right) && helper(l.right, r.left);
}
}
Leetcode 101. Symmetric Tree
最新推荐文章于 2018-06-20 09:51:14 发布