leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0390.cpp (249B)


0 class Solution {
1 public:
2 int lastRemaining(int n) const {
3 int head = 1;
5 for (int step = 1, dir = 1; n > 1; step *= 2, n /= 2, dir = !dir) {
6 head += dir || n % 2 ? step : 0;
7 }
9 return head;
10 }
11 };