Contains Duplicate in c

  • 1
    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
        if( (mp[nums[i]/32] & (1<<(nums[i]%32))) == 0 )
            mp[nums[i]/32] | (1<<(nums[i]%32));
            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

    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.