异或 时间复杂度O(n)
class Solution { public: int solve(vector<int>& a) { int n = a.size(); if(n == 0) return 0; int result = 0; for(int i = 0; i < n; i++){ result ^= a[i]; result ^= i+1; } return result; } };
异或 时间复杂度O(n)
class Solution { public: int solve(vector<int>& a) { int n = a.size(); if(n == 0) return 0; int result = 0; for(int i = 0; i < n; i++){ result ^= a[i]; result ^= i+1; } return result; } };