Page tree
Skip to end of metadata
Go to start of metadata

1.실패..

 



2.

// 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();
    }


3.

//Runtime: 14 ms, faster than 5.60% of Java online submissions for Maximize Sum Of Array After K Negations.
//Memory Usage: 38.7 MB, less than 23.14% of Java online submissions for Maximize Sum Of Array After K Negations.

public int largestSumAfterKNegations(int[] A, int K) {
        int count = K;
        while (count != 0) {

            Arrays.sort(A);
            A[0] = -A[0];
            count--;
        }

        return Arrays.stream(A).sum();
    }



  • No labels