[프로그래머스][2017 팁스타운] 예상 대진표

2020. 4. 7. 13:36프로그래머스/LEVEL 2

class Solution
{
    public int solution(int n, int a, int b)
    {
        int answer = 1;
            
        
        if(a>b){
           answer = roundCount(a,b);
        }else{
           answer = roundCount(b,a);
        }
        return answer;
    }
    
    private int roundCount(int bignum,int minnum){
        int answer =1;
         while(true){
                if(bignum%2==0 && bignum==minnum+1){
                    break;
                }
                
                if(bignum%2 ==0 ){
                    bignum= bignum/2;
                
                }else{
                    bignum= bignum/2 +1;
                }
                
                if(minnum%2 == 0 ){
                    minnum= minnum/2;
                }else{
                    minnum= minnum/2 +1;
                }
                answer ++;
            }
        return answer;
    }
}