콘솔창 & 윈도우창/코딩 테스트

프로그래머스 LV.2 점프와 순간이동

뽀또치즈맛 2025. 4. 6. 12:38

 

GitHub :https://github.com/kwon1232/CodingTest/tree/main/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4/2/12980.%E2%80%85%EC%A0%90%ED%94%84%EC%99%80%E2%80%85%EC%88%9C%EA%B0%84%E2%80%85%EC%9D%B4%EB%8F%99

 

#include <iostream>
using namespace std;

int solution(int n)
{
    int ans = 0;
    
    while(n > 0)
    {
        if (n % 2 == 0) n/=2;
        else 
        {
            n -= 1;
            ans++;
        }
        
    }

    return ans;
}

 

 

문제 링크

https://school.programmers.co.kr/learn/courses/30/lessons/12980