-
[Programmers] Lv2. ํผ๋ก๋(kotlin)SW Test/Programmers 2022. 10. 22. 17:07๋ฐ์ํ
๋ฌธ์
https://school.programmers.co.kr/learn/courses/30/lessons/87946 ์์
https://school.programmers.co.kr/learn/courses/30/lessons/87946 ํ์ด
- ๋ฐฑํธ๋ํน ๊ธฐ๋ฒ์ ์ด์ฉํ๋ฉด ์์ฝ๊ฒ ํ ์ ์์ต๋๋ค.
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์ ํน์ฑ์ ๋ง๊ฒ ํจ์๋ฅผ ๋ง์ด ์ตํ์ ๐ฝ
๋ฐ์ํ'SW Test > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Programmers] Lv2.๋ชจ์์ฌ์ (kotlin) (0) 2022.10.22 [Programmers] Lv2. ์ฐ์ ๋ถ๋ถ ์์ด(kotlin) (0) 2022.10.22 [Programmers] Lv2. ์ฃผ์ฐจ ์๊ธ ๊ณ์ฐ(kotlin) (0) 2022.10.22 [Programmers] Lv2.k์ง์์์ ์์ ๊ฐ์ ๊ตฌํ๊ธฐ(kotlin) (0) 2022.10.12 [Programmers] Lv2.ํ๋ฆฐํฐ(kotlin) (0) 2022.09.30