One line JAVA Solution!!! :P


  • 4
    C
    public boolean isSameTree(TreeNode p, TreeNode q) {
    return p==null&&q==null? true:p==null||q==null||p.val!=q.val? false:isSameTree(p.left,q.left)&&isSameTree(p.right,q.right);
    }

  • 0
    D
    return p == null || q == null ? p == null && q == null : (p.val == q.val && (isSameTree(p.left, q.left) && isSameTree(p.right, q.right)));

  • 0
    return (p == null) == (q == null) && (p == null || p.val == q.val && (isSameTree(p.left, q.left) && isSameTree(p.right, q.right)));

  • 0
    S

    Though the code is just one line, the readability has taken the toll.


Log in to reply
 

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