Created
October 30, 2015 19:26
-
-
Save mengdiwang/2c95db260c4cb241e4c8 to your computer and use it in GitHub Desktop.
Missing Number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int missingNumber(vector<int>& nums) { | |
int sum = 0; | |
for(int i=0; i<nums.size(); i++) | |
{ | |
sum += nums[i]; | |
} | |
return (1+nums.size())*nums.size()/2 - sum; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment