https://school.programmers.co.kr/learn/courses/30/lessons/77484?language=kotlin
class Solution {
fun solution(lottos: IntArray, win_nums: IntArray): IntArray {
var answer: IntArray = intArrayOf()
var countA = 0
var countB = 0
var bestRank = 0
var worstRank = 0
lottos.map {
if(win_nums.contains(it)) {
countA++
}
if(it == 0) {
countB++
}
}
when(countA){
6 -> worstRank = 1
5 -> worstRank = 2
4 -> worstRank = 3
3 -> worstRank = 4
2 -> worstRank = 5
1 -> worstRank = 6
0 -> worstRank = 6
}
when(countA + countB){
6 -> bestRank = 1
5 -> bestRank = 2
4 -> bestRank = 3
3 -> bestRank = 4
2 -> bestRank = 5
1 -> bestRank = 6
0 -> bestRank = 6
}
answer += bestRank
answer += worstRank
return answer
}
}
크게 생각하지 않고 순수하게 적어봤다..
속도가 조금 아쉽다..
'Code KATA' 카테고리의 다른 글
Programmers 숫자 짝꿍 with Kotlin (0) | 2023.12.13 |
---|---|
Programmers 옹알이 (2) with Kotlin (1) | 2023.12.12 |
Programmers 기사단원의 무기 with Kotlin (0) | 2023.12.08 |
Programmers 덧칠하기 with Kotlin (1) | 2023.12.07 |
Programmers 소수 만들기 with Kotlin (0) | 2023.12.06 |