크게 어렵지 않았다. 왜 LV2 인지 모르겠음.
#include <iostream>
using namespace std;
int solution(int n)
{
int ans = 0;
for (; n != 0; n /= 2)
if (n % 2 == 1)
ans++;
return ans;
}
'Coding_Test 연습 > Programmers' 카테고리의 다른 글
[프로그래머스] (C++) LV2 n^2 배열 자르기 (0) | 2022.06.05 |
---|---|
[프로그래머스] (C++) LV2 3 x n 타일링 (0) | 2022.06.04 |
[프로그래머스] (C++) LV2 이진 변환 반복하기 (0) | 2022.06.04 |
[프로그래머스] (C++) LV2 모음 사전 (0) | 2022.06.03 |
[프로그래머스] (C++) LV2 전력망을 둘로 나누기 (0) | 2022.06.02 |