0ms java solution


  • 0
    H
     public boolean isSameTree(TreeNode p, TreeNode q) {
            if(p!=null&&q!=null){
                return (p.val==q.val)&&isSameTree(p.left,q.left)&&isSameTree(p.right,q.right);
            }else if(p==null&&q==null){
                return true;
            }else{
                return false;
            }
        }

  • 0
    A

    You can simplify it even more. Instead of doing

            else if(p==null&&q==null){
                return true;
            }else{
                return false;
            }
    

    just write

            else return p == null && q == null;

  • 0
    J

    same answer guys.


Log in to reply
 

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