https://school.programmers.co.kr/learn/courses/30/lessons/12911
아까 전에 푼 문제에서 가져왔다
https://donghyk2.tistory.com/47
날먹 개 꿀
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int get_one_cnt(int num)
{
int res = 0;
int multi = 1;
while (2 * multi <= num)
multi *= 2;
while (num > 0 && multi >= 1)
{
if (num - multi >= 0)
{
res++;
num -= multi;
}
multi /= 2;
}
// cout << res << '\n';
return res;
}
int solution(int n) {
int one_cnt = get_one_cnt(n);
while (get_one_cnt(++n) != one_cnt);
return n;
}
'<algorithm> > 프로그래머스' 카테고리의 다른 글
프로그래머스 짝지어 제거하기 c++ (0) | 2023.05.26 |
---|---|
프로그래머스 피보나치 수 c++ (0) | 2023.05.25 |
프로그래머스 숫자의 표현 c++ (0) | 2023.05.25 |
프로그래머스 이진 변환 반복하기 c++ (0) | 2023.05.25 |
프로그래머스 최댓값과 최솟값 c++ (0) | 2023.05.25 |