We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ed8b592 commit 852fdbeCopy full SHA for 852fdbe
0290-word-pattern/0290-word-pattern.py
@@ -0,0 +1,22 @@
1
+class Solution:
2
+ def wordPattern(self, pattern: str, s: str) -> bool:
3
+ patternMap, wordMap = {}, {}
4
+ words = s.split(" ")
5
+ if len(words) != len(pattern):
6
+ return False
7
+ for char, word in zip(pattern, words):
8
+ if char not in patternMap:
9
+ if word in wordMap:
10
11
+ else:
12
+ patternMap[char] = word
13
+ wordMap[word] = char
14
15
+ if patternMap[char] != word:
16
17
+ return True
18
+
19
20
+pattern = "abba"
21
+s = "dog cat cat dog"
22
+print(Solution().wordPattern(pattern, s))
0 commit comments