Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lv.2] 숫자 변환하기 #171

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

[Lv.2] 숫자 변환하기 #171

wants to merge 1 commit into from

Conversation

say-young516
Copy link
Contributor

@say-young516 say-young516 commented May 18, 2023

🔗 Related Issues

🔍 문제

프로그래머스 - 숫자 변환하기

✅ 풀이 방법

📜 최종 소스코드

function solution(x, y, n) {
    const q=[];
    q.push([y,0]);
    while(q.length>0){
        let cur=q.shift();
        if(cur[0]===x) {
          return cur[1];
        }
        if(cur[0]-n>x&&(cur[0]-n)%1===0) {
            q.push([cur[0]-n,cur[1]+1]);
        }else if(cur[0]-n===x) return cur[1]+1;
        if(cur[0]%2===0&&cur[0]/2>x){ 
            q.push([cur[0]/2,cur[1]+1]);
        }else if(cur[0]/2===x) return cur[1]+1;
        if(cur[0]%3===0&&cur[0]/3>x) {
            q.push([cur[0]/3,cur[1]+1]);
        }else if(cur[0]/3===x) return cur[1]+1;
          
    }
    return -1;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

[Lv.2] 숫자 변환하기
1 participant