diff --git a/2201/220102-CN.cpp b/2201/220102-CN.cpp new file mode 100644 index 0000000..e4d3225 --- /dev/null +++ b/2201/220102-CN.cpp @@ -0,0 +1,18 @@ +#include + +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; +} diff --git a/2201/CMakeLists.txt b/2201/CMakeLists.txt index b367a11..20e68cc 100644 --- a/2201/CMakeLists.txt +++ b/2201/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2201) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2201 220101.cpp) \ No newline at end of file +ADD_EXECUTABLE(2201 220102-CN.cpp) \ No newline at end of file