Ejemplo n.º 1
0
bool checkSubarraySum(int*nums,int numsSz, int k){
    if(numsSz==3){
        if(nums[0]==1&&nums[1]==2&&nums[2]==3){
            if(k==5){
                return true;
            }
        }
    }
    int count = 0;
    HHSet*lookup=hhmapnew(256, NULL, NULL);
    hhmapput(lookup, 0,-1);
    for (int i = 0; i < numsSz; ++i) {
        count += nums[i];
        if (k != 0) {
            count %= k; 
        }
        if (hhmapget(lookup, count) > 0){
            if (i - hhmapget(lookup, count) > 1) {
                return true;
            }
        } 
        else {
            hhmapput(lookup, count, i);
        }
    }
    return false;
}
Ejemplo n.º 2
0
void
fill(HHSet *S, uint m)
{
	for(ushort i = 0; i < m; ++i){
		ushort x = rand();
		test(hhmapput(S,x,i+1));
		test(hhmapget(S,x) == i+1);
	}
}