그냥 해당값 맨앞으로 빼주고 전체제거해도되고
큐써서 처리해도되고 상관없을듯
정답
class Solution {
fun timeRequiredToBuy(tickets: IntArray, k: Int): Int {
var ticketList = tickets.toMutableList()
var res=0
for (i in 0 until k){
res+=1
val temp = ticketList.removeAt(0) - 1
if (temp>0){
ticketList.add(temp)
}
}
while (ticketList[0]!=0){
if (ticketList[0]==1){
res+=1
return res
}
res+=ticketList.size
ticketList=ticketList.map { it-1 }.filter { it>0 }.toMutableList()
}
return res
}
}
'알고리즘' 카테고리의 다른 글
릿코드 129. Sum Root to Leaf Numbers 코틀린 (0) | 2024.04.15 |
---|---|
릿코드 950. Reveal Cards In Increasing Order 코틀린 (0) | 2024.04.11 |
릿코드 1700. Number of Students Unable to Eat Lunch 코틀린 (0) | 2024.04.08 |
릿코드 678. Valid Parenthesis String 코틀린 (0) | 2024.04.07 |
릿코드 1249. Minimum Remove to Make Valid Parentheses 코틀린 (0) | 2024.04.06 |