您的位置:首页 > 其它

101. Symmetric Tree

2016-02-14 01:10 417 查看
树相关的问题一般都是递归

public class Solution {

    public boolean isSymmetric(TreeNode root) {

        if(root==null)return true;

        return isMirror(root.left,root.right);

    }

    public boolean isMirror(TreeNode p,TreeNode q){

        if(p==null&&q==null)return true;

        if(p==null||q==null)return false;

        if(p.val==q.val&&isMirror(p.left,q.right)&&isMirror(p.right,q.left))return true;

        else return false;

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: