글
프로그래머스 C# 예상 대진표(JAVA)
프로그래밍
2023. 2. 11. 14:01
728x90
SMALL
using System;
class Solution
{
public int solution(int n, int a, int b)
{
int answer = 0;
int index = 0;
/// a를 2로 나눈 몫+나머지, b를 2로 나눈 몫+나머지
while(a != b)
{
index++;
a = a/2+a%2;
b = b/2+b%2;
}
return index;
}
}
/// 라운드에서 위로 올라갈 때마다 번호가 바뀌는 방법을 응용했다.
자바
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;
}
}
class Solution
{
public int solution(int n, int a, int b)
{
return Integer.toBinaryString((a-1)^(b-1)).length();
}
}
728x90
'프로그래밍' 카테고리의 다른 글
프로그래머스 레벨2 C# 연속 부분 수열 합의 개수(Hash.Count, HashSet, Skip, Take, JAVA) (0) | 2023.02.11 |
---|---|
프로그래머스 C# 행렬의 곱셈(3중 for문, JAVA) (0) | 2023.02.11 |
프로그래머스 문자열 내의 p와 y의 개수(JAVA, toLowerCase().split(""), equals) (0) | 2023.02.11 |
프로그래머스 JAVA 폰켓몬 (0) | 2023.02.09 |
프로그래머스 레벨0 안전지대(C#, JAVA) try catch(Exception e) (0) | 2023.02.09 |