728x90
가까운 수
import kotlin.math.absoluteValue
class Solution {
fun solution(array: IntArray, n: Int) = array.sorted().minWithOrNull(compareBy { (it - n).absoluteValue })!!
}
369게임
class Solution {
fun solution(order: Int) = order.toString().count { it == '3' || it == '6' || it == '9' }
}
암호 해독
class Solution {
fun solution(cipher: String, code: Int): String {
var answer: String = ""
for (i in code-1 until cipher.length step(code))
answer += cipher[i]
return answer
}
}
대문자와 소문자
class Solution {
fun solution(my_string: String) = my_string.map {
if (it.isLowerCase()) it.uppercaseChar()
else it.lowercaseChar()
}.joinToString("")
}
728x90