1863.cpp (467B)
1 class Solution { 2 public: 3 int subsetXORSum(const vector<int> &nums) const { 4 const int n = size(nums); 5 int res = 0; 6 7 for (uint16_t mask = 1; mask < (1 << n); mask++) { 8 uint16_t crnt = mask, acc = 0; 9 while (crnt) { 10 const uint8_t idx = countr_zero(crnt); 11 acc ^= nums[idx]; 12 crnt ^= 1 << idx; 13 } 14 res += acc; 15 } 16 17 return res; 18 } 19 };