package leetcode;

/**
 * https://leetcode.com/problems/most-common-word/
 */
public class Problem819 {
    public String mostCommonWord(String paragraph, String[] banned) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem819 prob = new Problem819();
        System.out.println(prob.mostCommonWord(
            "Bob hit a ball, the hit BALL flew far after it was hit.",
            new String[]{"hit"})); // ball
    }
}

@@ -12,16 +12,113 @@
 tcode;%0A%0A
+import java.util.HashMap;%0Aimport java.util.HashSet;%0Aimport java.util.Map;%0Aimport java.util.Set;%0A%0A
 /**%0A * h
@@ -276,84 +276,325 @@
     
-// TODO%0A        return null
+Set%3CString%3E bannedWords = new HashSet%3C%3E();%0A        for (String b :banned) %7B%0A            bannedWords.add(b)
 ;%0A    
+ 
-%7D%0A%0A    public static void main(String%5B%5D arg
+   %7D%0A        String%5B%5D words = paragraph.split(%22%5C%5Cs+%7C!%7C%5C%5C?%7C'%7C,%7C;%7C%5C%5C.%22);%0A        Map%3CString, Integer%3E map = new HashMap%3C%3E();%0A        String maxWord = %22%22;%0A        int max = 0;%0A        for (String word : word
 s) %7B
@@ -606,205 +606,539 @@
     
+   
-Problem819 prob = new Problem819();%0A        System.out.println(prob.mostCommonWord(%0A            %22Bob hit a ball, the hit BALL flew far after it was hit.%22,%0A            new String%5B%5D%7B%22hit%22%7D)); // ball
+ word = word.toLowerCase();%0A            if (word.isEmpty() %7C%7C bannedWords.contains(word)) %7B%0A                continue;%0A            %7D%0A            int newMax = 0;%0A            if (!map.containsKey(word)) %7B%0A                newMax = 1;%0A                map.put(word, newMax);%0A            %7D else %7B%0A                newMax = map.get(word) + 1;%0A                map.put(word, newMax);%0A            %7D%0A            if (max %3C newMax) %7B%0A                max = newMax;%0A                maxWord = word;%0A            %7D%0A        %7D%0A        return maxWord;
 %0A   

Solve problem 819