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.
2 parents e487919 + 8948d67 commit 215ed15Copy full SHA for 215ed15
python/290-Word-Pattern.py
@@ -0,0 +1,16 @@
1
+class Solution:
2
+ def wordPattern(self, pattern: str, s: str) -> bool:
3
+ words = s.split(" ")
4
+ if len(pattern) != len(words):
5
+ return False
6
+ charToWord = {}
7
+ wordToChar = {}
8
+
9
+ for c, w in zip(pattern, words):
10
+ if c in charToWord and charToWord[c] != w:
11
12
+ if w in wordToChar and wordToChar[w] != c:
13
14
+ charToWord[c] = w
15
+ wordToChar[w] = c
16
+ return True
0 commit comments