Sentence Similarity


  • 0

    Click here to see the full article post


  • 0

    No need for such optimization, since words1 and words2 are never longer than 56 (despite 1000 being allowed) and pairs is never longer than 73 (despite 2000 being allowed).


  • 0

    (Edit: got fixed) Isn't space complexity O(P)? Why do you add N? Those intermediate objects exist only one at a time, not all at the same time. So they can occupy the same space over and over again.


  • 0

    Corrected, thanks.


  • 0
    S

    @awice I think you forgot to change O(N) to O(P) in the space complexity analysis.


  • 0
    G

    Why use contains? Can we just use equals? If we use contains, something like "asd#cvb".contains("sd#cv") will return true, but "sd" and "cv" are not similar in this case


  • 0
    L

    @genius1wjc what do you mean? The code does full string comparison, not substring.


  • 0
    G

    @lch04 I couldn't view the question and the solution anymore. As you said, it should do full string comparison, not substring. That's why we should just use equals rather than contains. Or maybe the solution has been edited to use equals now


  • 0
    S

    I don't think these solutions are very flexible. It assumes an ordering of words1 and words2, as you can see by the second for loop in the java solution and the zip() usage in the Python solution. Coudn't the sentence be "similar" even if the words that are similar don't line up exactly with each other?


  • 0
    N

    This solution seems assume it only needs to check the word similarity at the same position. But the question does not seem have that assumption ?


Log in to reply
 

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