프로그래머스-예상대진표

이호영·2022년 4월 9일
0

프로그래머스-Level.2

목록 보기
22/36
class Solution{
    public int solution(int n, int a, int b){
        return round(Math.min(a, b), Math.max(a, b));
//         순서정리
    }
    
    public int round(int a, int b){
        int cnt=1;
        
        while(true){
            if (b%2==0 && a+1==b) break;
            if(a%2!=0) a+=1;
            if(b%2!=0) b+=1;
            a/=2;
            b/=2;
            cnt++;
        }
        
        return cnt;
    }
}

0개의 댓글