int solution(int n) { int right = n & -n; // 가장 오른쪽 1인 비트의 값 int x = n + right; // 원래 수 + 가장 오른쪽 비트 return x | (((x ^ n) >> 2) / right); // 줄어든 1의 개수만큼 오른쪽부터 채운다 }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter