Closed antop-dev closed 1 month ago
쉽지 않았다...
import java.util.*
class Solution {
fun predictPartyVictory(senate: String): String {
val n = senate.length
val rq = LinkedList<Int>()
val dq = LinkedList<Int>()
senate.forEachIndexed { i, c ->
when (c) {
'R' -> rq += i
'D' -> dq += i
}
}
while (rq.isNotEmpty() && dq.isNotEmpty()) {
val i = minOf(rq.peek(), dq.peek())
if (i == rq.peek()) {
dq.poll()
rq += rq.poll() + n
} else if (i == dq.peek()) {
rq.poll()
dq += dq.poll() + n
}
}
return if (rq.size > dq.size) "Radiant" else "Dire"
}
}
https://leetcode.com/problems/dota2-senate/