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;
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter