/dota2_senate.kt Secret
Created
November 15, 2021 03:09
leetcode 649
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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