원본 문제 : https://programmers.co.kr/learn/courses/30/lessons/42587?language=kotlin
<첫번째>
import java.util.*
data class Doc (val priority: Int, val idx: Int)
class Solution {
fun solution(priorities: IntArray, location: Int): Int {
var answer = 1
val printList: LinkedList<Doc> = LinkedList<Doc>()
for ( i in priorities.indices)
printList.add(Doc(priorities[i], i))
while(printList.size > 1) {
val firstDoc: Doc = printList.peek()
for( i in 1 until printList.size) {
if(firstDoc.priority < printList[i].priority) {
printList.add(printList.poll())
break
}
if(i == printList.size - 1) {
if(firstDoc.idx == location) return answer
printList.poll()
answer++
}
}
}
return answer
}
}
<두번째> 2020/06/05
import java.util.*
data class Doc(val p: Int, val i: Int)
fun solution(priorities: IntArray, location: Int): Int {
val list: LinkedList<Doc> = LinkedList<Doc>()
priorities
.forEachIndexed { index, value ->
list.add(Doc(value, index))
}
var answer: Int = 0
while (true) {
val now = list.poll()
if (list.any { now.p < it.p }) {
list.add(now)
} else {
answer++
if (now.i == location)
break
}
}
return answer
}
'프로그래머스 > 코딩연습1' 카테고리의 다른 글
[프로그래머스] 기능개발(42586)(Kotlin) (0) | 2020.01.14 |
---|---|
[프로그래머스] 실패율 (42889)(Kotlin) (0) | 2020.01.14 |
[프로그래머스] 다리를 지나는 트럭(42583)(Kotlin) (0) | 2020.01.13 |
[프로그래머스] 네트워크(java)(43162) (0) | 2019.06.11 |
[프로그래머스] 여행경로 (java)(43164) (0) | 2019.06.10 |
댓글