Is Symmetric Tree

^_^


    public boolean isSymmetric(TreeNode root) {
        if(root == null) return true;
        else return isSymmetric(root.left, root.right);
    }

    private boolean isSymmetric(TreeNode left, TreeNode right){
        if(left == null || right == null) return left == right;
        else return left.val == right.val && isSymmetric(left.left, right.right) && isSymmetric(left.right, right.left);
    }

results matching ""

    No results matching ""