用异或解决
class Solution { public: int missingNumber(vector<int>& nums) { int length = nums.size(); if(length <= 0) return -1; int res = 0; for(int i = 1;i <= nums.size();i++){ res = res ^ i ^ nums[i-1]; } return res; } };
https://blog.csdn.net/ebowtang/article/details/50457902