Not Fast, Just another approach by Priority_Queue


  • 0
    S
    bool containsDuplicate(vector<int>& nums) {
        
        if (nums.size() < 2) return false;
    
        std::priority_queue<int, vector<int>, std::greater<int> > pq(nums.begin(), nums.end() );
        
        int pre = pq.top();
        int cur = 0;
        pq.pop();
        while(!pq.empty())
        {
            cur = pq.top();
            pq.pop();
            if (pre == cur)
                return true;
            pre = cur;
        }
        return false;

Log in to reply
 

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