Joey LIU | NANTSOU


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
class Solution {
    public boolean isSymmetric(TreeNode root) {
        if (root != null) {
            return isMirror(root.left, root.right);
        } else {
            return true;
        }
    }

    private boolean isMirror(TreeNode l, TreeNode r) {
        if (l != null && r != null) {
            return l.val == r.val && isMirror(l.left, r.right) && isMirror(l.right, r.left);
        } else  {
            return l == null && r == null;
        }
    }
}