Unable to submit Java solution while C++ pass


#1

public class Solution {
public int cntBits(ArrayList A) {
long MOD = 1000000007;
long diffBits =0;
long count=0;

    for(int i =0;i<31;++i){
        count=0;
        
        for(int j =0;j<A.size();j++){
            if((A.get(j)&(1<<i))!=0){
                count++;
            }
        }
        diffBits = (diffBits + 2*count*(A.size()-count))%MOD;  
    }
    // diffBits = (diffBits)%MOD;
    return (int)diffBits;
}

}

My above solution didn’t work if i used data type as int count=0;
while if i use the same code in cpp with int count=0; it works
not sure why it was failing in java