Skip to content

Commit 413c074

Browse files
authored
Create 2997. Minimum Number of Operations to Make Array XOR Equal to K (#468)
2 parents 19a5c82 + e3391a3 commit 413c074

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
int minOperations(vector<int>& v, int k) {
4+
int n=v.size();
5+
int ans=0;
6+
for(int i=0;i<=30;i++) {
7+
int b=0;
8+
for(int j=0;j<n;j++) {
9+
if(((v[j]>>i)&1)==1)
10+
b=b^1;
11+
}
12+
if(((k>>i)&1)!=b)
13+
ans++;
14+
}
15+
return ans;
16+
}
17+
};

0 commit comments

Comments
 (0)