Don't you think the SUM method will cause the integer overflow if it is tested with extremely large numbers?
Don't you think the SUM method will cause the integer overflow if it is tested with extremely large numbers?

We can avoid that using the code below. The idea is similar to using sum.
class Solution { public: int missingNumber(vector<int>& nums) { int res = nums.size(); for (int i = 0; i < nums.size(); ++i){ res += i; res = nums[i]; } return res; } };
actually we can replace the + and  signs with ^ and it'll still work (bit manipulation).
class Solution { public: int missingNumber(vector<int>& nums) { int res = nums.size(); for (int i = 0; i < nums.size(); ++i){ res ^= i; res ^= nums[i]; } return res; } };