728x90
점의 위치 구하기
class Solution {
fun solution(dot: IntArray) =
if (dot[0] > 0){
if (dot[1] > 0){
1
}else
4
}else{
if (dot[1] > 0)
2
else
3
}
}
2차원으로 만들기
class Solution {
fun solution(num_list: IntArray, n: Int)= num_list.toList().chunked(n)
}
공 던지기
class Solution {
fun solution(numbers: IntArray, k: Int) = numbers[((k-1)*2)%numbers.size]
}
배열 회전시키기
class Solution {
fun solution(numbers: IntArray, direction: String): IntArray {
var answer: IntArray = intArrayOf()
if (direction == "right"){
answer = answer.plus(numbers.last())
answer = answer.plus(numbers.slice(0 until numbers.size-1))
}else{
answer = answer.plus(numbers.slice(1 .. numbers.size-1))
answer = answer.plus(numbers.first())
}
return answer
}
}
728x90