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 하면 됨
[프로그래머스] n^2배열 자르기 (0) | 2024.12.10 |
---|---|
[프로그래머스] 괄호 회전하기 (0) | 2024.12.10 |
[프로그래머스] 귤고르기 (0) | 2024.12.09 |
[프로그래머스] 영어 끝말잇기 (0) | 2024.12.09 |
[프로그래머스] 점프와 순간 이동 (0) | 2024.12.09 |