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 4835515 commit afee3f9Copy full SHA for afee3f9
leetcode.com 290. Word Pattern/main.py
@@ -0,0 +1,25 @@
1
+class Solution:
2
+ def wordPattern(self, pattern: str, s: str) -> bool:
3
+ ss = s.split()
4
+
5
+ if len(pattern) != len(ss):
6
+ return False
7
8
+ c2word = {}
9
+ word2c = {}
10
11
+ for idx in range(len(pattern)):
12
+ c = pattern[idx]
13
+ word = ss[idx]
14
15
+ if c not in c2word.keys():
16
+ c2word[c] = word
17
+ elif c2word[c] != word:
18
19
20
+ if word not in word2c.keys():
21
+ word2c[word] = c
22
+ elif word2c[word] != c:
23
24
25
+ return True
0 commit comments