티스토리 뷰

728x90
SMALL

내풀이

function solution(n,a,b){
    let num=0;
    while(true){
        a=Math.ceil(a/2);
        b=Math.ceil(b/2);
        num++;
        if(a===b){
            return num;
        }
    }
}

다른사람풀이

function solution(n,a,b){
    let num=0;
    while(a!==b){
        a=Math.ceil(a/2);
        b=Math.ceil(b/2);
        num++;
    }
    return num;
}

그냥 바로 풀렸다 내풀이나 다른사람풀이나 복잡도면에서는 차이가 없다.

근데 밑에풀이가 조금더 깔끔?해보이는

728x90
LIST
댓글
공지사항