SW Test/Programmers
[Programmers] Lv2. ํผ๋ก๋(kotlin)
An effort will never betray ๐
2022. 10. 22. 17:07
๋ฐ์ํ
๋ฌธ์
์์
ํ์ด
- ๋ฐฑํธ๋ํน ๊ธฐ๋ฒ์ ์ด์ฉํ๋ฉด ์์ฝ๊ฒ ํ ์ ์์ต๋๋ค.
import kotlin.math.*
class Solution {
var answer = -1
fun getResult(k: Int, dungeons: Array<IntArray>, check: List<Boolean>){
var flag = false
for(i in 0 until check.size){
if(!check[i] && k >= dungeons[i][0]){
flag = true
getResult(k-dungeons[i][1], dungeons, check.toMutableList().apply{ this[i] = true })
}
}
if(!flag){
answer = max(answer, check.count{it})
}
}
fun solution(k: Int, dungeons: Array<IntArray>): Int {
getResult(k, dungeons, List(dungeons.size){false})
return answer
}
}
์ฐธ๊ณ
- ํจ์ํ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด์ธ kotlin์ ํน์ฑ์ ๋ง๊ฒ ํจ์๋ฅผ ๋ง์ด ์ตํ์ ๐ฝ
๋ฐ์ํ