• Home
  • About
    • Moon photo

      Moon

      개발자는 자고 싶다.

    • Learn More
    • Twitter
    • Facebook
    • Instagram
    • Github
    • Steam
  • Posts
    • All Posts
    • All Tags
  • Projects

프로그래머스 - 92334 신고 결과 받기 풀이

03 Jul 2022

Reading time ~1 minute

문제

92334 신고 결과 받기

screencapture

풀이

리포트의 중복을 제거하고 Array 타입을 Array<Pair<String, String>> 형태로 바꾼다.

kotlin code

val reportPairArray = report.toSet().map { it.split(' ').let { l -> Pair(l[0], l[1] )} }.toTypedArray()

k번 이상 신고가 되어 사용 중지된 유저들을 구한다

kotlin code

val stopUsers = reportPairArray.groupingBy { it.second }.eachCount().filter { it.value >= k }.keys

리포트를 신고자 이름을 key로 하는 맵으로 변경한다.

kotlin code

val reportMap = reportPairArray.groupBy { it.first }.toMap()

각 유저별로 처리 결과 메일을 받은 횟수를 배열에 담아 return 한다.

kotlin code

return IntArray(id_list.size) {
    reportMap[id_list[it]]?.count { c -> c.second in stopUsers } ?: 0
}

답

kotlin code

class Solution {
    fun solution(id_list: Array<String>, report: Array<String>, k: Int): IntArray {
        val reportPairArray = report.toSet().map { it.split(' ').let { l -> Pair(l[0], l[1] )} }.toTypedArray()
        val stopUsers = reportPairArray.groupingBy { it.second }.eachCount().filter { it.value >= k }.keys
        val reportMap = reportPairArray.groupBy { it.first }.toMap()

        return IntArray(id_list.size) {
            reportMap[id_list[it]]?.count { c -> c.second in stopUsers } ?: 0
        }
    }
}


programmerskotlin코틀린프로그래머스Lv.1풀이 Share Tweet +1