6ms C Solution, beats 100%


  • 0
    W

    static int table[1048576 / 256];

    bool containsDuplicate(int* nums, int numsSize) {

      int m = 16, n = numsSize;
      while(m < n){
          m <<= 1;
      }
      m <<= 1;
      memset(table, 0, m * sizeof(int));
      int *is = table, *ip = is, *ie = is + m;
      int zcount = 0;
      m --;
      int *ps = nums, *pe = ps + n, *p=ps;
      for(; p < pe; ++p){
          int *ip = is + (*p & m);
          for(; *ip != 0; ){
              if(*ip == *p){
                  return true;
              }
              if(++ip == ie){
                  ip = is;
              }
          }
          if(*p == 0 && zcount ++ >= 1){
              return true;
          }
          *ip = *p;
      }
      return false;
    

    }


Log in to reply
 

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