-
Notifications
You must be signed in to change notification settings - Fork 14
/
890-kir3i.java
26 lines (26 loc) · 936 Bytes
/
890-kir3i.java
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 {
public Map<Character, Character> trans = new HashMap<Character, Character>();
public Set<Character> used = new HashSet<Character>();
public List<String> findAndReplacePattern(String[] words, String pattern) {
int sz = pattern.length();
List<String> ans = new ArrayList<String>();
for(String w: words) {
Boolean ok = true;
trans.clear();
used.clear();
for(int i=0; i<sz && ok; i++) {
if(!trans.containsKey(pattern.charAt(i))) {
ok &= !used.contains(w.charAt(i));
trans.put(pattern.charAt(i), w.charAt(i));
used.add(w.charAt(i));
}
else {
ok &= (trans.get(pattern.charAt(i)) == w.charAt(i));
}
}
if(ok)
ans.add(w);
}
return ans;
}
}