💻 문제 출처 : 프로그래머스_예상 대진표
public class Solution {
class Solution {
public int solution(int n, int a, int b) {
int min = Math.min(a, b);
int max = Math.max(a, b);
int round = 1;
while(true) {
if(max - min == 1 && (min - 1) / 2 == (max - 1) / 2) {
return round;
}
min = min % 2 == 1 ? (min + 1) / 2 : min / 2;
max = max % 2 == 1 ? (max + 1) / 2 : max / 2;
round++;
}
}
}
class Solution {
public int solution(int n, int a, int b) {
return Integer.toBinaryString((a-1)^(b-1)).length();
}
}
class Solution {
public int solution(int n, int a, int b) {
int round = 0;
while(a != b) {
a = a/2 + a%2;
b = b/2 + b%2;
round++;
}
return round;
}
}