๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level2)์˜ˆ์ƒ ๋Œ€์ง„ํ‘œ

by ์ฃผ๋ฐœ2 2020. 3. 16.
๋ฐ˜์‘ํ˜•

https://programmers.co.kr/learn/courses/30/lessons/12985

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

์ฝ”๋“œ

class Solution
{
    public int solution(int n, int a, int b)
    {
        int answer = 0;
        while(a != b){
            answer ++;
            a = (a+1)/2;
            b = (b+1)/2;
        }
        return answer;
    }
}

ํ’€์ด

๋ฐฑ์ค€ 1057๋ฒˆ ํ† ๋„ˆ๋จผํŠธ ๋ฌธ์ œ์™€ ๋™์ผํ•˜๋‹ค. ๋”ฐ๋ผ์„œ ํ’€์ด๋Š” ์•„๋ž˜ ์‚ฌ์ดํŠธ ์ฐธ๊ณ  !

ํ’€์ด <

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€