공부기록/프로그래머스

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

메델 2023. 11. 6. 07:50
import java.util.*;

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

        return ans;
    }
}