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 | 0b25fe6d662871e3426e6be4ba28caa6fe035817 (patch) | |
tree | 0bf9ff2a8d28952aaca191ab8eeb967076ecce8a | |
parent | 98c9d8d31fa1239daa47d20bcd6e77d77bc84726 (diff) | |
download | crupest-0b25fe6d662871e3426e6be4ba28caa6fe035817.tar.gz crupest-0b25fe6d662871e3426e6be4ba28caa6fe035817.tar.bz2 crupest-0b25fe6d662871e3426e6be4ba28caa6fe035817.zip |
import(solutions): Add problem 17.04 .
-rw-r--r-- | works/solutions/cpp/17.04.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/works/solutions/cpp/17.04.cpp b/works/solutions/cpp/17.04.cpp new file mode 100644 index 0000000..07ac7ae --- /dev/null +++ b/works/solutions/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;
+ }
+};
|