cnt subarrays with xor k
Wed Jan 22 2025 17:42:21 GMT+0000 (Coordinated Universal Time)
Saved by
@javads
public class Solution {
public int solve(int[] A, int B) {
HashMap<Integer,Integer> hm=new HashMap<>();
int cnt=0;
int sum=0;
hm.put(0,1);
for(int i=0;i<A.length;i++){
sum^=A[i];
if(hm.containsKey(sum^B)){
cnt+=hm.get(sum^B);
}if(hm.containsKey(sum)){
hm.put(sum,hm.get(sum)+1);
}
else{
hm.put(sum,1);
}
}
return cnt;
}
}
content_copyCOPY
Comments