Given two integer arrays startTime and endTime and given an integer queryTime.
给两个整数数组和一个查询时间
The ith student started doing their homework at the time startTime[i] and finished it at time endTime[i].
第 i 个学生 在startTime[i]开始写作业,在endTime[i] 时 完成作业。
Return the number of students doing their homework at time queryTime. More formally, return the number of students where queryTime lays in the interval [startTime[i], endTime[i]] inclusive.
返回在查询时间内写作业的学生。事实上,要返回的是在[startTime[i], endTime[i]]区间内 包含查询时间的学生个数。
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/number-of-students-doing-homework-at-a-given-time
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
class Solution {
public int busyStudent(int[] startTime, int[] endTime, int queryTime) {
int ans =0;
for (int i = 0; i < startTime.length; i++) {
if(startTime[i]<=queryTime && queryTime<=endTime[i]){
ans++;
}
}
return ans;
}
}