Skip to content

Instantly share code, notes, and snippets.

@terracotta-ko
Created November 15, 2021 03:09
leetcode 649
class Solution {
fun predictPartyVictory(senate: String): String {
val canVotes = intArrayOf(0, 0)
val bans = intArrayOf(0, 0)
val queue = mutableListOf<Int>()
for(c in senate) {
if (c == 'R') {
canVotes[0] += 1
queue.add(0)
} else {
canVotes[1] += 1
queue.add(1)
}
}
while(canVotes[0] > 0 && canVotes[1] > 0) {
val s = queue.first()
queue.removeAt(0)
if(bans[s] > 0) {
canVotes[s] -= 1
bans[s] -= 1
} else {
bans[s xor 1] += 1
queue.add(s)
}
}
return if (canVotes[0] > 0) {
"Radiant"
} else {
"Dire"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment