24ms beating 99% using bitset with little hack


  • 2
    Y
    class Solution {
    public:
        bool containsDuplicate(vector<int>& nums) {
            bitset<2000000> bs;
            for(int x: nums) {
                x+=1000000; //deal with negative
                if(bs.test(x)){
                    return true;
                }
                bs.set(x);
            }
            return false;
        }
    };

Log in to reply
 

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