题目:

题解:
func lastRemaining(n int) int {
a1 := 1
k, cnt, step := 0, n, 1
for cnt > 1 {
if k%2 == 0 { // 正向
a1 += step
} else { // 反向
if cnt%2 == 1 {
a1 += step
}
}
k++
cnt >>= 1
step <<= 1
}
return a1
}



















![[000-01-008].Seata案例应用](https://i-blog.csdnimg.cn/blog_migrate/fd927ba652f0ca8c66438b2648574b41.png)