[Leetcode] 1375. III lamp switch

Here Insert Picture Description
Here Insert Picture Description

Here Insert Picture Description
Here Insert Picture Description

Problem-solving ideas

In fact, very simple, I did not understand the meaning of problems

Questions askedallThe number of lights are lit

Code

class Solution {
public:
    int numTimesAllBlue(vector<int>& light) {
        int res = 0;
        vector<bool>blue(light.size()+1, false); 
        priority_queue<int,vector<int>,less<int>>pq;
        pq.push(0);
        blue[0] = true;
        for(int i = 0; i < light.size(); i++)
        {
            if(light[i] < pq.top())
            {
                if(pq.size() == pq.top())
                {
                    blue[pq.top()] = true;
                    res++;
                    
                }
            }
            else if(light[i] > pq.top())
            {
                if((blue[pq.top()] == true) && light[i] == pq.top() + 1)
                {
                    blue[light[i]] = true;
                    res++;
                }
            }
            pq.push(light[i]);
        }
        return res;
    }
};

=After sending read other people explanations update=

To what large root heap ah. . .

image.png

He published 192 original articles · won praise 5 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_40691051/article/details/104730369