leetcodeSolution 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; 4 5 for (int step = 1, dir = 1; n > 1; step *= 2, n /= 2, dir = !dir) { 6 head += dir || n % 2 ? step : 0; 7 } 8 9 return head; 10 } 11 };