Solution

PHOTO EMBED

Sat Feb 12 2022 17:19:51 GMT+0000 (Coordinated Universal Time)

Saved by @ianbyeon #c

int solution(int n) {
    int right = n & -n;    // 가장 오른쪽 1인 비트의 값
    int x     = n + right; // 원래 수 + 가장 오른쪽 비트
    
    return x | (((x ^ n) >> 2) / right); // 줄어든 1의 개수만큼 오른쪽부터 채운다
}
content_copyCOPY