Java Solution simple


#1

public class Solution {
// DO NOT MODIFY THE LIST. IT IS READ ONLY
public int hammingDistance(final List A) {
long ans=0;
long n = A.size();
long count =0;
for(int i=0;i<31;i++){
count =0;
for(int j=0;j<n;j++){
if((A.get(j)&(1<<i))!=0){
count++;
}
}
ans = (ans + count*(n-count)*2)%1000000007;
}
return (int)ans;
}
}


#2

Can you explain why you used and operation with the left shift operation?