Symmetric Tree

Symmetric Tree

问题:

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).

思路:

  dfs

我的代码:

public class Solution {
    public boolean isSymmetric(TreeNode root) {
        if(root == null)    return true;
        return helper(root.left,root.right);
    }
    public boolean helper(TreeNode left, TreeNode right)
    {
        if(left == null && right == null)   return true;
        if(left == null || right == null)   return false;
        return left.val == right.val && helper(left.left, right.right) && helper(left.right, right.left);
    }
}
View Code
原文地址:https://www.cnblogs.com/sunshisonghit/p/4320815.html