80场双周赛
第三题困难题
class Solution {
public boolean matchReplacement(String s, String sub, char[][] m) {
Map<Character, Set<Character>> map = new HashMap();
for (int i = 0; i < m.length; i++) {
if (!map.containsKey(m[i][0])) {
Set<Character> set = new HashSet();
set.add(m[i][1]);
map.put(m[i][0], set);
} else {
Set<Character> set = map.get(m[i][0]);
set.add(m[i][1]);
}
}
char[] a = s.toCharArray();
char[] b = sub.toCharArray();
int x = a.length;
int y = b.length;
for (int i = 0; i <= x - y; i++) {
int j = 0;
for (; j < y; j++) {
if (a[i + j] != b[j]) {
if (!map.containsKey(b[j])) break;
if (!map.get(b[j]).contains(a[i + j])) break;
}
}
if (j == y) return true;
}
return false;
}
}