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. . .