Leetcode 268 Solution
This article provides solution to leetcode question 268 (missing-number)
Access this page by simply typing in "lcs 268" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/missing-number
Solution
class Solution {
public:
int missingNumber(vector<int>& nums) {
int n = nums.size() + 1;
int total = 0;
for (int i = 0; i < nums.size(); i++)
total += nums[i];
return (n * (n - 1) / 2) - total;
}
};