Skip to content

Commit 2a8d3c1

Browse files
committed
2019-09-08
1 parent 04d1899 commit 2a8d3c1

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed
Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
11
class Solution(object):
2-
def wordPattern(self, pattern, str):
2+
def wordPattern(self, pattern, s):
33
"""
44
:type pattern: str
55
:type str: str
66
:rtype: bool
77
"""
8-
s = str.split(" ")
8+
s = s.split(" ")
99
if len(pattern) != len(s):
1010
return False
11-
record = [0 for i in range(0, 26)] #记录下pattern里每个字母出现的次数
12-
hashmap = dict()
13-
14-
for i, word in enumerate(s):
15-
t = ord(pattern[i]) - ord("a")
16-
17-
if word not in hashmap.keys():
18-
if record[t] > 0:
19-
return False
20-
hashmap[word] = pattern[i]
21-
record[t] = 1
11+
dic = {}
12+
for i, char in enumerate(pattern):
13+
if char not in dic:
14+
dic[char] = s[i]
2215
else:
23-
if hashmap[word] != pattern[i]:
16+
if dic[char] != s[i]:
2417
return False
25-
26-
return True
27-
28-
29-
18+
19+
return len(set(dic.values())) == len(dic.values())
20+

0293.翻转游戏/0293-翻转游戏.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ def generatePossibleNextMoves(self, s):
66
"""
77
res = []
88
for i in range(len(s) - 1):
9-
if s[i:i+2] == "++":
10-
res.append(s[:i] + "--" + s[i+2:])
9+
if s[i:i + 2] == "++":
10+
res.append(s[:i] + "--" + s[i + 2:])
1111
return res

0 commit comments

Comments
 (0)