add: 220102 CN
This commit is contained in:
parent
92baff81df
commit
706548af13
|
|
@ -0,0 +1,18 @@
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
// O(log(n))
|
||||||
|
static int lastRemaining(int n) {
|
||||||
|
int cnt = 0, ret = 1;
|
||||||
|
for (int i = n; i >>= 1; ++cnt);
|
||||||
|
for (int i = 0; i < cnt; ++i, n >>= 1)
|
||||||
|
ret += !(1 & i) || (1 & n) ? (1 << i) : 0;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::printf("%d\n", Solution::lastRemaining(1));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -3,4 +3,4 @@ PROJECT(2201)
|
||||||
|
|
||||||
SET(CMAKE_CXX_STANDARD 23)
|
SET(CMAKE_CXX_STANDARD 23)
|
||||||
|
|
||||||
ADD_EXECUTABLE(2201 220101.cpp)
|
ADD_EXECUTABLE(2201 220102-CN.cpp)
|
||||||
Loading…
Reference in New Issue