Skip to content

Commit 65a7e85

Browse files
committed
feat: add solutions to lc problem: No.1450. Number of Students Doing
Homework at a Given Time
1 parent 0776d44 commit 65a7e85

File tree

6 files changed

+132
-2
lines changed

6 files changed

+132
-2
lines changed

solution/1400-1499/1450.Number of Students Doing Homework at a Given Time/README.md

+47-1
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,61 @@
7272
<!-- 这里可写当前语言的特殊实现逻辑 -->
7373

7474
```python
75-
75+
class Solution:
76+
def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:
77+
count, n = 0, len(startTime)
78+
for i in range(n):
79+
count += startTime[i] <= queryTime <= endTime[i]
80+
return count
7681
```
7782

7883
### **Java**
7984

8085
<!-- 这里可写当前语言的特殊实现逻辑 -->
8186

8287
```java
88+
class Solution {
89+
public int busyStudent(int[] startTime, int[] endTime, int queryTime) {
90+
int count = 0, n = startTime.length;
91+
for (int i = 0; i < n; ++i) {
92+
if (startTime[i] <= queryTime && queryTime <= endTime[i]) {
93+
++count;
94+
}
95+
}
96+
return count;
97+
}
98+
}
99+
```
100+
101+
### **C++**
102+
103+
```cpp
104+
class Solution {
105+
public:
106+
int busyStudent(vector<int>& startTime, vector<int>& endTime, int queryTime) {
107+
int count = 0, n = startTime.size();
108+
for (int i = 0; i < n; ++i) {
109+
if (startTime[i] <= queryTime && queryTime <= endTime[i]) {
110+
++count;
111+
}
112+
}
113+
return count;
114+
}
115+
};
116+
```
83117
118+
### **Go**
119+
120+
```go
121+
func busyStudent(startTime []int, endTime []int, queryTime int) int {
122+
count, n := 0, len(startTime)
123+
for i := 0; i < n; i++ {
124+
if startTime[i] <= queryTime && queryTime <= endTime[i] {
125+
count++
126+
}
127+
}
128+
return count
129+
}
84130
```
85131

86132
### **...**

solution/1400-1499/1450.Number of Students Doing Homework at a Given Time/README_EN.md

+47-1
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,59 @@ The third student started doing homework at time 3 and finished at time 7 and wa
6969
### **Python3**
7070

7171
```python
72-
72+
class Solution:
73+
def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:
74+
count, n = 0, len(startTime)
75+
for i in range(n):
76+
count += startTime[i] <= queryTime <= endTime[i]
77+
return count
7378
```
7479

7580
### **Java**
7681

7782
```java
83+
class Solution {
84+
public int busyStudent(int[] startTime, int[] endTime, int queryTime) {
85+
int count = 0, n = startTime.length;
86+
for (int i = 0; i < n; ++i) {
87+
if (startTime[i] <= queryTime && queryTime <= endTime[i]) {
88+
++count;
89+
}
90+
}
91+
return count;
92+
}
93+
}
94+
```
95+
96+
### **C++**
97+
98+
```cpp
99+
class Solution {
100+
public:
101+
int busyStudent(vector<int>& startTime, vector<int>& endTime, int queryTime) {
102+
int count = 0, n = startTime.size();
103+
for (int i = 0; i < n; ++i) {
104+
if (startTime[i] <= queryTime && queryTime <= endTime[i]) {
105+
++count;
106+
}
107+
}
108+
return count;
109+
}
110+
};
111+
```
78112
113+
### **Go**
114+
115+
```go
116+
func busyStudent(startTime []int, endTime []int, queryTime int) int {
117+
count, n := 0, len(startTime)
118+
for i := 0; i < n; i++ {
119+
if startTime[i] <= queryTime && queryTime <= endTime[i] {
120+
count++
121+
}
122+
}
123+
return count
124+
}
79125
```
80126

81127
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
int busyStudent(vector<int>& startTime, vector<int>& endTime, int queryTime) {
4+
int count = 0, n = startTime.size();
5+
for (int i = 0; i < n; ++i) {
6+
if (startTime[i] <= queryTime && queryTime <= endTime[i]) {
7+
++count;
8+
}
9+
}
10+
return count;
11+
}
12+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
func busyStudent(startTime []int, endTime []int, queryTime int) int {
2+
count, n := 0, len(startTime)
3+
for i := 0; i < n; i++ {
4+
if startTime[i] <= queryTime && queryTime <= endTime[i] {
5+
count++
6+
}
7+
}
8+
return count
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public int busyStudent(int[] startTime, int[] endTime, int queryTime) {
3+
int count = 0, n = startTime.length;
4+
for (int i = 0; i < n; ++i) {
5+
if (startTime[i] <= queryTime && queryTime <= endTime[i]) {
6+
++count;
7+
}
8+
}
9+
return count;
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution:
2+
def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:
3+
count, n = 0, len(startTime)
4+
for i in range(n):
5+
count += startTime[i] <= queryTime <= endTime[i]
6+
return count

0 commit comments

Comments
 (0)