Leetcode1450. 在既定时间做作业的学生人数

题意

给定每一个学生的开始时间和结束时间,问某个时间点有多少人正在做作业

思路

  • 我们只要开一个数组,用count[i]表示这个时间点有多少人在做作业,那么我们每读入[开始时间, 结束时间]就将其对应区间的count[i]加一

代码

class Solution {
public:
    int busyStudent(vector<int>& startTime, vector<int>& endTime, int queryTime) {
        vector<int> count(1001, 0);
        for(int i=0;i<startTime.size();i++) {
            int st = startTime[i];
            int ed = endTime[i];
            for(int j=st;j<=ed;j++) {
                count[j]++;
            }
        }
        return count[queryTime];
    }
};
如有转载,请注明出处QAQ
原文地址:https://www.cnblogs.com/MartinLwx/p/14311320.html