LeetCode #1450. Number of Students Doing Homework at a Given Time

题目

1450. Number of Students Doing Homework at a Given Time


解题方法

遍历数组判断queryTime是否在startTime[i]和endTime[i]之间即可,返回满足条件的个数。
时间复杂度:O(n)
空间复杂度:O(1)


代码

class Solution:
    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:
        rat = 0
        for i in range(len(startTime)):
            if startTime[i] - 1 < queryTime < endTime[i] + 1:
                rat += 1
        return rat
posted @ 2020-12-01 16:09  老鼠司令  阅读(60)  评论(0编辑  收藏  举报