Share my accepted java solution

  • 2
    public boolean isSameTree(TreeNode p, TreeNode q) {
        return helper(p,q);    
    private boolean helper(TreeNode p, TreeNode q){
        if(p==null && q==null) return true;
        if(p==null || q==null) return false;
        if(p.val != q.val) return false;
        return helper(p.left, q.left) && helper(p.right, q.right);

  • 0

    Why do you need helper method if helper and isSameTree args & return types are same?

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.