비트연산은 자주 풀었기 때문에 구현에 어려움은 없었다.
홀수 / 짝수 나눠서 계산 하면된다.
#include <vector>
using namespace std;
vector<long long> solution(vector<long long> numbers)
{
vector<long long> answer;
for (int i = 0; i < numbers.size(); i++)
{
long long temp = 1;
while ((numbers[i] & temp) > 0)
temp = temp << 1;
answer.push_back(numbers[i] + temp - (temp >> 1));
}
return answer;
}'Coding_Test 연습 > Programmers' 카테고리의 다른 글
| [프로그래머스] (C++) LV2 영어 끝말잇기 (0) | 2022.06.01 |
|---|---|
| [프로그래머스] (C++) LV2 삼각 달팽이 (0) | 2022.06.01 |
| [프로그래머스] (C++) LV2 피로도 (0) | 2022.06.01 |
| [프로그래머스] (C++) LV2 2 x n 타일링 (0) | 2022.05.31 |
| [프로그래머스] (C++) LV2 큰 수 만들기 (0) | 2022.05.30 |