[LeetCode] 819. Most Common Word(Kotlin)

0

LeetCode

목록 보기
34/58
post-thumbnail

[LeetCode] 819. Most Common Word(Kotlin)

풀이

class Solution {
    private val delimiters = arrayOf<String>(
            " ",
            "\"",
            "!",
            "?",
            "\'",
            ",",
            ";",
            "."
        )

    fun mostCommonWord(paragraph: String, banned: Array<String>): String
        = paragraph
            .split(*delimiters)
            .map{ it.lowercase() }
            .filter{ it.isNotBlank() && !banned.contains(it.toString()) }
            .groupingBy{ it }
            .eachCount() 
            .maxBy{ it.value }
            .key
}
profile
Be able to be vulnerable, in search of truth

0개의 댓글