inblog logo
|
stupefyee
    알고리즘문제풀기

    [JAVA 문제 풀이] 282. 예상 대진표

    프로그래머스 (12985)
    Stupefyee's avatar
    Stupefyee
    May 27, 2025
    [JAVA 문제 풀이] 282. 예상 대진표
    Contents
    내가 작성한 코드다른 사람의 코드
    school.programmers.co.kr
    https://school.programmers.co.kr/learn/courses/30/lessons/12985
    notion image
     

    내가 작성한 코드

    class Solution { public int solution(int n, int a, int b) { int round = 1; // a와 b가 같은 라운드에서 만날 때까지 반복 while (true) { // a와 b가 바로 붙어있는 번호이면서, 둘 중 하나가 짝수이고, 둘의 차이가 1이면 만나는 경우 if ((a % 2 == 0 && a - 1 == b) || (b % 2 == 0 && b - 1 == a)) { return round; } // 다음 라운드 번호로 갱신 >> 두 수 중 하나를 홀수로 두기 위해 +1 a = (a + 1) / 2; b = (b + 1) / 2; round++; } } }
     

    다른 사람의 코드

    class Solution { public int solution(int n, int a, int b) { //(a-1) XOR (b-1)값을 이진수 문자열로 변환한 길이 세기 return Integer.toBinaryString((a - 1) ^ (b - 1)).length(); } }
     
    Share article
    Contents
    내가 작성한 코드다른 사람의 코드

    stupefyee

    RSS·Powered by Inblog