Skip to content

Commit

Permalink
Find and Replace Pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
rinwf committed Aug 22, 2018
1 parent bfc401f commit f420369
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions lc890.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class Solution:
def findAndReplacePattern(self, words, pattern):
"""
:type words: List[str]
:type pattern: str
:rtype: List[str]
"""
ans=[]

for word in words:
d=dict() #
for i in range(len(word)):
if word[i] not in d:
d[word[i]]=pattern[i]
else:
if d[word[i]]!=pattern[i]:
break
else:
d=dict() #
for i in range(len(word)):
if pattern[i] not in d:
d[pattern[i]]=word[i]
else:
if d[pattern[i]]!=word[i]:
break
else:
ans.append(word)
return ans




words = ["abc","deq","mee","aqq","dkd","ccc"]
pattern = "abb"


s=Solution()
print(s.findAndReplacePattern(words,pattern))

0 comments on commit f420369

Please sign in to comment.