class Solution {
public String mostCommonWord (String paragraph, String[] banned) {
Set<String> set = new HashSet<>();
for (String ban: banned) set.add(ban);
Map<String, Integer> map = new HashMap<>();
int maxCnt = 0;
String maxWord = "";
Character[] punctuations = new Character[]{'!', '?', '\'', ',', ';', '.'};
for (Character punctuation: punctuations) paragraph = paragraph.replace(puctuation, ' ');
String[] words = paragraph.split(" ");
for (int i = 0; i < words.length; i++) {
String word = words[i].toLowerCase();
if (word != "" && set.contains(word) == false) {
map.put(word, map.getOrDefault(word, 0) + 1);
if (map.get(word) > maxCnt) {
maxCnt = map.get(word);
maxWord = word;
}
}
}
return maxWord;
}
}