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 | eff23cb3a8c33a9e58f463ba500a38cf8f7562dc (patch) | |
| tree | a294c345c52f5a438028f8dabbf647ad460798d6 /works/solutions/cpp | |
| parent | ce1d40841a662386522d3c52fe413d424e42e32c (diff) | |
| download | crupest-eff23cb3a8c33a9e58f463ba500a38cf8f7562dc.tar.gz crupest-eff23cb3a8c33a9e58f463ba500a38cf8f7562dc.tar.bz2 crupest-eff23cb3a8c33a9e58f463ba500a38cf8f7562dc.zip  | |
import(solutions): Add problem 17.04 .
Diffstat (limited to 'works/solutions/cpp')
| -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;
 +    }
 +};
  | 
