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; } };