C# 알고리즘 코드카타
80. 예상 대진표
잼잼재미
2024. 2. 23. 10:21
using System;
class Solution
{
public int solution(int n, int a, int b)
{
int answer = 1;
int first = a;
int second = b;
while(true)
{
if(first-second == 1 || second-first == 1)
{
if(first > second)
{
if(first % 2 == 0) break;
}
else if(first % 2 != 0) break;
}
answer++;
if(first % 2 == 0) first /= 2;
else
{
if(first == 1) first = 1;
else
{
first = (first + 1) / 2;
}
}
if(second % 2 == 0) second /= 2;
else
{
if(second == 1) second = 1;
else
{
second = (second + 1) / 2;
}
}
}
return answer;
}
}