Cute Blue Flying Butterfly
본문 바로가기
알고리즘

[Kotlin] programmers 예상 대진표

by jordancancode 2024. 12. 13.

출처

https://school.programmers.co.kr/learn/courses/30/lessons/12985

 

 

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

 

풀이

import kotlin.math.*

class Solution {
    
    fun getNextNum(i : Int): Int {
        return (i+1)/2
    }
    
    fun solution(n: Int, a: Int, b: Int): Int {
        var answer = 1
        var newA = a
        var newB = b
        while ((abs(newA - newB) > 1) || getNextNum(newA) != getNextNum(newB)) {
            newA = getNextNum(newA)
            newB = getNextNum(newB)
            answer++
        }

        return answer
    }
}
반응형