diff options
author | crupest <crupest@outlook.com> | 2020-05-23 14:12:07 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-05-23 14:12:07 +0800 |
commit | d2c6f96bb3c94869251f7a709c783fcbbf82d276 (patch) | |
tree | c8756bd14bb4a458e41366c32bb2e24a83eeade7 | |
parent | e3efc844f67b0cfa9410caee79a7e9354800387d (diff) | |
download | solutions-d2c6f96bb3c94869251f7a709c783fcbbf82d276.tar.gz solutions-d2c6f96bb3c94869251f7a709c783fcbbf82d276.tar.bz2 solutions-d2c6f96bb3c94869251f7a709c783fcbbf82d276.zip |
Add problem 17.04 .
-rw-r--r-- | cpp/17.04.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/cpp/17.04.cpp b/cpp/17.04.cpp new file mode 100644 index 0000000..07ac7ae --- /dev/null +++ b/cpp/17.04.cpp @@ -0,0 +1,21 @@ +#include <vector>
+
+using std::vector;
+
+class Solution
+{
+public:
+ int missingNumber(vector<int> &nums)
+ {
+ const int size = nums.size();
+ const int sum = size * (size + 1) / 2;
+
+ int real_sum = 0;
+ for (auto i : nums)
+ {
+ real_sum += i;
+ }
+
+ return sum - real_sum;
+ }
+};
|