상세 컨텐츠

본문 제목

[프로그래머스] 예상 대진표

💯ProblemSolving/문제 풀이-Java

by :부셔져버린개발자 2024. 12. 9. 13:23

본문

       문제 요약        

- 문제

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

 

         소스코드        

class Solution
{
    public int solution(int n, int a, int b)
    {
        int answer = 1;
        while(true) {
             a = (a + 1) / 2;
             b = (b + 1) / 2;
            if(a == b) {
                break;
            }
            answer += 1;
        }
        return answer;
    }
}

 

(1 2) (3 4) (5 6) (7 8)

(1 2) (3 4)

1 2 

 

=> ( n + 1 ) / 2 하면 됨

728x90

관련글 더보기