Contains Duplicate in c


  • 1
    J
    bool containsDuplicate(int* nums, int numsSize) {
    int i,count;
    count = numsSize/32+1;
    int mp[count];
    for(i=0;i<count;i++) mp[i] = 0;  //初始化bitmap为0
    for(i=0;i<numsSize;i++){
        if( (mp[nums[i]/32] & (1<<(nums[i]%32))) == 0 )
            mp[nums[i]/32] | (1<<(nums[i]%32));
        else
            return true;
    }
    return false;
    

    }

    I use a bitmap struct to check is a value is dumplicate,Why this code is runtime error? Is the manipulate of division?


  • 0
    J

    I know the reason.The bit-map struct can't use to this algorithm,because there is not a range for the bit-map.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.