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 ec2b88a commit a896b69Copy full SHA for a896b69
Hash Table/Easy/290.Word Pattern.md
@@ -0,0 +1,36 @@
1
+# 题目
2
+
3
+根据pattern和str,找到是否符合这个pattern匹配模式。
4
5
+**举例:**
6
7
+* pattern = "abba", str = "dog cat cat dog" should return true.
8
+* pattern = "abba", str = "dog cat cat fish" should return false.
9
+* pattern = "aaaa", str = "dog cat cat dog" should return false.
10
+* pattern = "abba", str = "dog dog dog dog" should return false.
11
12
+**注意:**
13
14
+假设pattern只包含小写字母,而str包含由空格分隔的小写字母。
15
16
+# 思路
17
18
+对于python,巧妙使用map和find函数即可。
19
20
+# 代码
21
22
+**python:**
23
24
+``` python
25
+class Solution:
26
+ def wordPattern(self, pattern, str):
27
+ """
28
+ :type pattern: str
29
+ :type str: str
30
+ :rtype: bool
31
32
+ t = str.split(' ')
33
+ return list(map(pattern.find, pattern)) == list(map(t.index, t))
34
+```
35
36
0 commit comments