2
public List<String> findAndReplacePattern(String[] words, String pattern) {3
List<String> result = new ArrayList<>();4
for (String word : words) {5
Map<Character, Character> map = new HashMap<>();6
Set<Character> set = new HashSet<>();8
for (; i < word.length(); i++) {9
char ch = pattern.charAt(i);10
if (map.get(ch) == null) {11
if (set.contains(word.charAt(i))) break;12
map.put(ch, word.charAt(i));13
set.add(word.charAt(i));15
char mc = map.get(ch);16
if (mc != word.charAt(i)) break;19
if (i == pattern.length()) result.add(word);