-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path프린터.kt
25 lines (25 loc) · 817 Bytes
/
프린터.kt
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
data class Paper(val location: Int, val priority: Int)
class Solution {
fun solution(priorities: IntArray, location: Int): Int {
val deque = ArrayDeque<Paper>()
val temp = ArrayDeque<Paper>()
for (i in 0..priorities.lastIndex) {
deque.add(Paper(i, priorities[i]))
}
while (deque.isNotEmpty()) {
val mx = deque.maxByOrNull { it.priority }
while (true) {
val first = deque.removeFirst()
if (first.location == mx?.location) {
break
} else {
deque.addLast(first)
}
}
if (mx?.location == location) {
return priorities.size - deque.size
}
}
return priorities.size
}
}