# 【LeetCode】268. Missing Number

Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.

For example,
Given nums = [0, 1, 3] return 2.

Note:

Your algorithm should run in linear runtime complexity. Could you implement it using only constant extra space complexity?

class Solution {
public:
int missingNumber(vector<int>& nums) {
double prox;
int size=nums.size();
int sum=0;

for(int i=0;i<size;i++){
sum+=nums[i];
}

prox=-0.5+sqrt(0.25+2*sum);

if(1+ceil(prox)==size){

return prox+1;

}else{
int c=ceil(prox);
return c*(c+1)/2-sum;
}
}
};

#### LeetCode 268. Missing Number（缺失数字）

2016-04-11 02:15:40

#### leetcode_c++：Missing Number（268）

2016-06-19 12:24:34

#### leetcode 268: Missing Number

2015-09-08 09:19:12

#### leetcode【268 Missing Number】【Python】

2016-09-08 17:22:13

#### <LeetCode OJ> 268. Missing Number

2016-01-04 19:22:42

#### [leetcode] 268.Missing Number

2015-08-24 10:30:06

#### 【LeetCode】268 Missing Number （java实现）

2015-08-29 12:28:01

#### LeetCode268——Missing Number相濡以沫不如相忘于江湖

2015-08-24 21:46:34

#### 268. Missing Number（重要！）

2016-07-13 16:46:58

#### LeetCode之268. Missing Number

2018-03-05 15:14:55