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;
}
Example #2
0
int
main(void)
{
	uint n = 256;
	uint m = 150;
	HHSet *S = hhmapnew(n,NULL,NULL);
	fill(S,m);
	test(m == S->T->m);
	hhsetfree(S);
	return 0;
}