首页 > 其他 > 详细

Symmetric Tree

时间:2015-03-07 19:57:29      阅读:294      评论:0      收藏:0      [点我收藏+]

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

 

Symmetric Tree

原文:http://www.cnblogs.com/sunshisonghit/p/4320815.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!