From da919308b68c45670e288008be2a0f5dfc59d518 Mon Sep 17 00:00:00 2001 From: Lam Haoyin Date: Tue, 28 Dec 2021 00:31:13 +0800 Subject: [PATCH] add: 211227 --- 2112/211227.cpp | 14 ++++++++++++++ 2112/CMakeLists.txt | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 2112/211227.cpp diff --git a/2112/211227.cpp b/2112/211227.cpp new file mode 100644 index 0000000..4913ebd --- /dev/null +++ b/2112/211227.cpp @@ -0,0 +1,14 @@ +#include + +class Solution { +public: + static int findComplement(int num) { + unsigned t = 1; + for (int x = num; x; t <<= 1, x >>= 1); + return (t - 1) ^ num; + } +}; + +int main() { + std::printf("%d\n", Solution::findComplement(9)); +} \ No newline at end of file diff --git a/2112/CMakeLists.txt b/2112/CMakeLists.txt index d05e6fd..c0b2453 100644 --- a/2112/CMakeLists.txt +++ b/2112/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2112) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2112 211226.cpp) \ No newline at end of file +ADD_EXECUTABLE(2112 211227.cpp) \ No newline at end of file