Skip to content

Commit 2d22c59

Browse files
committed
Update word-pattern.cpp
1 parent 9336440 commit 2d22c59

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

C++/word-pattern.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Time: O(n)
2-
// Space: O(c), c is unique count of pattern and words
2+
// Space: O(c), c is unique count of pattern
33

44
class Solution {
55
public:
@@ -26,7 +26,7 @@ class Solution {
2626
if (!w2p.count(w) && !p2w.count(p)) {
2727
w2p[w] = p;
2828
p2w[p] = w;
29-
} else if (w2p[w] != p) {
29+
} else if (!w2p.count(w) || w2p[w] != p) {
3030
return false;
3131
}
3232
i = j + 1;

0 commit comments

Comments
 (0)