aboutsummaryrefslogtreecommitdiff
path: root/works/solutions/leetcode/cpp/17.04.cpp
blob: 07ac7aed3e1891af924be4473d69e18770bbaf2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
    }
};