:type words: List[str] :type pattern: str :rtype: List[str]
(self, words, pattern)
| 42 | |
| 43 | class Solution(object): |
| 44 | def findAndReplacePattern(self, words, pattern): |
| 45 | """ |
| 46 | :type words: List[str] |
| 47 | :type pattern: str |
| 48 | :rtype: List[str] |
| 49 | """ |
| 50 | |
| 51 | def translate_pattern(word): |
| 52 | result = ['0'] |
| 53 | current = '0' |
| 54 | patterns = {word[0]: '0'} |
| 55 | for i in word[1:]: |
| 56 | if patterns.get(i) is not None: |
| 57 | result.append(patterns.get(i)) |
| 58 | else: |
| 59 | current = str(int(current)+1) |
| 60 | patterns[i] = current |
| 61 | result.append(current) |
| 62 | |
| 63 | return ''.join(result) |
| 64 | |
| 65 | x = translate_pattern(pattern) |
| 66 | |
| 67 | result = [] |
| 68 | for i in words: |
| 69 | if x == translate_pattern(i): |
| 70 | result.append(i) |
| 71 | |
| 72 | return result |
nothing calls this directly
no outgoing calls
no test coverage detected