add: 220528 [cpp]
This commit is contained in:
parent
8025bdd5b5
commit
e112f8c395
|
|
@ -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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -3,4 +3,4 @@ PROJECT(2205)
|
||||||
|
|
||||||
SET(CMAKE_CXX_STANDARD 23)
|
SET(CMAKE_CXX_STANDARD 23)
|
||||||
|
|
||||||
ADD_EXECUTABLE(2205 220527.cpp)
|
ADD_EXECUTABLE(2205 220528.cpp)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue