Sum of paiwise hamming distance What modification shoul I do to tackle TLE


#1

public class Solution { // DO NOT MODIFY THE LIST. IT IS READ ONLY static int dist(int a , int b){ if(a==b)return 0; int count=0; while(a!=0 || b!=0){ if(a%2!=b%2){ count++; } a=a>>1; b=b>>1; } return count%1000000007; } public int hammingDistance(final List<Integer> A) { int l = A.size(); int res = 0; if(l<2)return 0; for(int i=0;i<l-1;i++){ for(int j=i+1;j<l;j++){ res = res%1000000007 + 2*dist(A.get(i),A.get(j))%100000007; } } return res%1000000007; } }