add: 220528 [cpp]

This commit is contained in:
Eat-Swap 2022-05-28 12:50:40 +08:00
parent 8025bdd5b5
commit e112f8c395
Signed by: Eatswap
GPG Key ID: BE661106A1F3FA0B
2 changed files with 17 additions and 1 deletions

16
cpp/2205/220528.cpp Normal file
View File

@ -0,0 +1,16 @@
#include <vector>
/**
* 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<int>& nums) {
int ans = 0;
for (int i = 1; i <= nums.size(); ++i)
ans ^= i ^ nums[i - 1];
return ans;
}
};

View File

@ -3,4 +3,4 @@ PROJECT(2205)
SET(CMAKE_CXX_STANDARD 23)
ADD_EXECUTABLE(2205 220527.cpp)
ADD_EXECUTABLE(2205 220528.cpp)