-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path290.py
More file actions
28 lines (26 loc) · 741 Bytes
/
290.py
File metadata and controls
28 lines (26 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution(object):
def wordPattern(self, pattern, str):
"""
:type pattern: str
:type str: str
:rtype: bool
"""
# word = str.split()
# pdict = {}
# wdict = {}
# ans = {}
# if len(pattern) != len(word):
# return False
# for k, v in zip(pattern, word):
# if k not in pdict:
# pdict[k] = v
# if v not in wdict:
# wdict[v] = k
# if pdict[k] != v or wdict[v]!=k:
# return False
# return True
# 方法2
words = str.split(' ')
if len(words) != len(pattern):
return False
return map(pattern.find, pattern) == map(words.index, words)