일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- DWG
- Python Code
- 시바견
- 파이썬
- t1
- 밴픽
- 운영체제
- shiba
- kaggle
- 715. Range Module
- Python
- 프로그래머스
- Convert Sorted List to Binary Search Tree
- 109. Convert Sorted List to Binary Search Tree
- Regular Expression
- iterator
- data science
- Python Implementation
- Substring with Concatenation of All Words
- LeetCode
- Generator
- 컴퓨터의 구조
- Protocol
- 30. Substring with Concatenation of All Words
- concurrency
- Decorator
- 43. Multiply Strings
- Class
- 315. Count of Smaller Numbers After Self
- attribute
Archives
- Today
- Total
Scribbling
[Java] LeetCode: 1606. Find Servers That Handled Most Number of Requests 본문
Computer Science/Java
[Java] LeetCode: 1606. Find Servers That Handled Most Number of Requests
focalpoint 2023. 8. 27. 04:41https://leetcode.com/problems/find-servers-that-handled-most-number-of-requests/description/
class Solution {
public List<Integer> busiestServers(int k, int[] arrival, int[] load) {
int[] counter = new int[k];
TreeSet<Integer> servers = new TreeSet<>();
for (int i = 0; i < k; i++) {
servers.add(i);
}
// [endTime, serverId]
Queue<int []> schedules = new PriorityQueue<>(new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
return o1[0] - o2[0];
}
});
for (int idx = 0; idx < arrival.length; idx ++) {
int curTime = arrival[idx];
int endTime = curTime + load[idx];
while (!schedules.isEmpty() && schedules.peek()[0] <= curTime) {
int serverId = schedules.poll()[1];
servers.add(serverId);
}
if (servers.size() == 0) {
continue;
}
Integer targetId = servers.ceiling(idx % k);
if (targetId == null) {
targetId = servers.first();
}
counter[targetId]++;
servers.remove(targetId);
schedules.offer(new int[] {endTime, targetId});
}
List<Integer> arr = Arrays.stream(counter).boxed().collect(Collectors.toList());
int max = Collections.max(arr);
List<Integer> ret = new ArrayList<>();
for (int i = 0; i < counter.length; i++) {
if (counter[i] == max) {
ret.add(i);
}
}
return ret;
}
}
'Computer Science > Java' 카테고리의 다른 글
[Java] 1481. Least Number of Unique Integers after K Removals (0) | 2024.02.16 |
---|---|
[Java 101] 435. Non-overlapping Intervals - Comparator (0) | 2023.03.15 |
[Java 101] 211. Design Add and Search Words Data Structure - trie (0) | 2023.03.11 |
[Java101] Trie Implementation (0) | 2023.03.08 |
[Java 101] 102. Binary Tree Level Order Traversal - Queue (0) | 2023.03.04 |