Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int lastRemaining(int n) {
- int res = 1, move = 1;
- bool left_right = true;
- while (n > 1)
- {
- if (left_right)
- res += move;
- else
- res += (n%2) ? move : 0;
- n /= 2;
- move *= 2;
- left_right = !left_right;
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement