题目:

题解:
class Solution {
public int lastRemaining(int n) {
int a1 = 1;
int k = 0, cnt = n, step = 1;
while (cnt > 1) {
if (k % 2 == 0) { // 正向
a1 = a1 + step;
} else { // 反向
a1 = (cnt % 2 == 0) ? a1 : a1 + step;
}
k++;
cnt = cnt >> 1;
step = step << 1;
}
return a1;
}
}






![[Linux]:基本指令(上)](https://img-blog.csdnimg.cn/img_convert/28ff5a40598423b5410d0b759ea2dc4d.png)











