Kotlin/코딩테스트

[프로그래머스] 다음에 올 숫자 - kotlin

깨노비 2023. 3. 12. 21:08
728x90
반응형

class Solution {
    fun solution(common: IntArray): Int {
        var answer: Int = common[common.size-1]
        val diff = common[1] - common[0]

        if (common.size > 2) {
            if (diff == common[2] - common[1]) {
                answer += diff
            } else {
                answer *= (common[1] / common[0])
            }
        } else {
            answer += diff
        }

        return answer
    }
}
728x90
반응형