Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

1.실패..

Code Block



2.

Code Block
// Runtime: 17 ms, faster than 42.59% of Java online submissions for Most Common Word.
//Memory Usage: 39.4 MB, less than 47.47% of Java online submissions for Most Common Word.


public String mostCommonWord(String paragraph, String[] banned) {
        String match = "[^\uAC00-\uD7A3xfe0-9a-zA-Z\\s]";
        paragraph = paragraph.replaceAll(match, " ");
        final String[] words = paragraph.split(" ");


        Map<String, Integer> dictionary = new HashMap<>();
        for (final String rawWord : words) {
            String word = rawWord.trim().toLowerCase();
            if (!word.isEmpty()) {
                dictionary.put(word, dictionary.getOrDefault(word, 0) + 1);
            }
        }

        for (final String ban : banned) {
            dictionary.remove(ban);
        }

        return dictionary.entrySet()
                .stream()
                .min(Map.Entry.comparingByValue(Comparator.reverseOrder()))
                .get()
                .getKey();
    }

...