-
[Programmers] Lv1. K๋ฒ์งธ ์(kotlin)SW Test/Programmers 2022. 7. 9. 16:09๋ฐ์ํ
๋ฌธ์
์์
ํ์ด
1. return ๊ฐ์ ๊ฐฏ์๋ commands ์๋งํผ ๊ฒฐ๊ณผ๊ฐ ์ ์ฅ์ด ๋ฉ๋๋ค.
2. commands์ index๋ฅผ ํ๋์ฉ ํ์ํ์ฌ List๋ก ๋ณ๊ฒฝ ํ subList ํจ์๋ก ๋ถ๋ถ ๋ฆฌ์คํธ๋ฅผ ๊ฐ์ ธ์ต๋๋ค.
3. ์ดํ sorted๋ก ์ ๋ ฌํ ๋ฆฌ์คํธ๋ฅผ ๊ฐ์ ธ์จ ๋ค์์ ์ํ๋ ์ธ๋ฑ์ค์ ๊ฐ์ ์ฐพ์ผ๋ฉด ๋ฉ๋๋ค.
class Solution { fun solution(array: IntArray, commands: Array<IntArray>): IntArray { return commands.mapIndexed{ index, i -> array.toList() .subList(commands[index][0] - 1, commands[index][1]) .sorted() .get(commands[index][2] -1) }.toIntArray() } }
์ฐธ๊ณ
- ํจ์ํ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด์ธ kotlin์ ํน์ฑ์ ๋ง๊ฒ ํจ์๋ฅผ ๋ง์ด ์ตํ์ ๐ฝ
- https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/sub-list.html
๋ฐ์ํ'SW Test > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Programmers] Lv1. ํฌ๋ ์ธ ์ธํ ๋ฝ๊ธฐ(kotlin) (0) 2022.07.13 [Programmers] Lv1.์์ ๋ง๋ค๊ธฐ(kotlin) (0) 2022.07.12 [Programmers] Lv1.๋ชจ์๊ณ ์ฌ(kotlin) (0) 2022.06.04 [Programmers] Lv1.์ฒด์ก๋ณต(kotlin) (0) 2022.06.02 [Programmers] Lv1. 2019 KAKAO BLIND RECUITMENT ์คํจ์จ(kotlin) (0) 2022.05.26