LeetCode 1450 Number of Students Doing Homework at a Given Time (Python)

Posted by 小明MaxMing on May 17, 2020

题目

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

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.

解题思路

遍历每个学生开始和结束做作业的时间,判断是否包含查询时刻

代码

class Solution:
    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:
        res = 0
        for s, e in zip(startTime, endTime):
            if s <= queryTime <= e:
                res += 1
        return res

视频讲解 YouTube<--欢迎点击订阅

视频讲解 bilibili<--欢迎点击订阅