코딩테스트 풀이/JAVA
[LeetCode/Easy] 1450. Number of Students Doing Homework at a Given Time
무지맘
2022. 12. 25. 22:06
1. Input
1) int 배열 startTime
2) int 배열 endTime
3) 정수 queryTime
4) i번째 학생은 [ startTime[i], endTime[i] ]까지 숙제를 했다.
2. Output
1) queryTime때 숙제를 하고 있던 학생의 수
3. Constraint
1) startTime.length == endTime.length
2) 1 <= startTime.length <= 100
3) 1 <= startTime[i] <= endTime[i] <= 1000
4) 1 <= queryTime <= 1000
4. Example
Input: startTime = [1,2,3], endTime = [3,2,7], queryTime = 4 -> Output: 1
설명:
- 0번째 학생: 1시부터 3시까지 숙제 -> 4시에는 하지 않았음
- 1번째 학셍: 2시부터 2시까지 숙제 -> 4시에는 하지 않았음
- 2번째 학생: 3시부터 7시까지 숙제 -> 4시에는 숙제중이었음
- 따라서 1을 반환한다.
5. Code
1) 첫 코드(2022/06/15)
int count = 0;
for(int i=0 ; i<startTime.length ; i++)
if(startTime[i]<=queryTime && queryTime<=endTime[i])
count++;
return count;