자윤이와고리즘/Code

[프로그래머스] 점프와 순간이동

EUJU 2019. 8. 13. 14:46
#include <iostream>
using namespace std;

int solution(int n)
{
    int ans = 0;
	int tmp = 0;
    while(true){
        if(n == 1){
            ans++;
            break;
        }
        
        if(n%2 == 0){
            n = n/2;
        }
        else{
            ans++;
            n = n/2 ;
        }

    }
    return ans;
}