diff --git a/cpp/2205/220528.cpp b/cpp/2205/220528.cpp new file mode 100644 index 0000000..a64f2b1 --- /dev/null +++ b/cpp/2205/220528.cpp @@ -0,0 +1,16 @@ +#include + +/** + * 268. Missing Number + * Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. + */ + +class Solution { +public: + int missingNumber(const std::vector& nums) { + int ans = 0; + for (int i = 1; i <= nums.size(); ++i) + ans ^= i ^ nums[i - 1]; + return ans; + } +}; diff --git a/cpp/2205/CMakeLists.txt b/cpp/2205/CMakeLists.txt index 6fafc44..b8cf7ea 100644 --- a/cpp/2205/CMakeLists.txt +++ b/cpp/2205/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2205) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2205 220527.cpp) +ADD_EXECUTABLE(2205 220528.cpp)