Click here to see the full article post
No need for such optimization, since
words2 are never longer than 56 (despite 1000 being allowed) and
pairs is never longer than 73 (despite 2000 being allowed).
(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.
@awice I think you forgot to change O(N) to O(P) in the space complexity analysis.
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
@genius1wjc what do you mean? The code does full string comparison, not substring.
@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
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?
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.