-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlc_890.py
More file actions
26 lines (21 loc) · 847 Bytes
/
lc_890.py
File metadata and controls
26 lines (21 loc) · 847 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
class Solution:
def findAndReplacePattern(self, words: List[str], pattern: str) -> List[str]:
ptFormat = []
if len(pattern) == 1:
return words
for i in range(len(pattern) - 1):
if (pattern[i] == pattern[i+1]):
ptFormat.append(1)
else:
ptFormat.append(0)
qualify = []
for i in words:
for j in range(len(pattern) - 1):
if (i[j] == i[j+1]) and (ptFormat[j] == 0):
break
elif (i[j] != i[j+1]) and (ptFormat[j] == 1):
break
elif (j == (len(pattern) - 2)):
qualify.append(i)
break
return qualify