package com.fishercoder.solutions;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class _890 {
    public static class Solution1 {
        public List<String> findAndReplacePattern(String[] words, String pattern) {
            List<String> result = new ArrayList<>();
            for (String word : words) {
                Map<Character, Character> map = new HashMap<>();
                Set<Character> set = new HashSet<>();
                boolean match = true;
                for (int i = 0; i < pattern.length(); i++) {
                    if (map.containsKey(pattern.charAt(i))) {
                        if (word.charAt(i) != map.get(pattern.charAt(i))) {
                            match = false;
                            break;
                        }
                    } else {
                        map.put(pattern.charAt(i), word.charAt(i));
                        if (!set.add(word.charAt(i))) {
                            match = false;
                        }
                    }
                }
                if (match) {
                    result.add(word);
                }
            }
            return result;
        }
    }
}

@@ -1273,11 +1273,1300 @@
  %7D%0A    %7D
+%0A%0A    public static class Solution2 %7B%0A        public List%3CString%3E findAndReplacePattern(String%5B%5D words, String pattern) %7B%0A            List%3CString%3E result = new ArrayList%3C%3E();%0A            for (String word : words) %7B%0A                if (matches(word, pattern)) %7B%0A                    result.add(word);%0A                %7D%0A            %7D%0A            return result;%0A        %7D%0A%0A        private boolean matches(String word, String pattern) %7B%0A            Map%3CCharacter, Character%3E map1 = new HashMap%3C%3E();//word -%3E p%0A            Map%3CCharacter, Character%3E map2 = new HashMap%3C%3E();//p -%3E word%0A            for (int i = 0; i %3C pattern.length(); i++) %7B%0A                if (!map1.containsKey(word.charAt(i))) %7B%0A                    map1.put(word.charAt(i), pattern.charAt(i));%0A                %7D%0A                if (map1.containsKey(word.charAt(i)) && map1.get(word.charAt(i)) != pattern.charAt(i)) %7B%0A                    return false;%0A                %7D%0A                if (!map2.containsKey(pattern.charAt(i))) %7B%0A                    map2.put(pattern.charAt(i), word.charAt(i));%0A                %7D%0A                if (map2.containsKey(pattern.charAt(i)) && map2.get(pattern.charAt(i)) != word.charAt(i)) %7B%0A                    return false;%0A                %7D%0A            %7D%0A            return true;%0A        %7D%0A    %7D
 %0A%7D%0A

add a solution for 890