Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 74c4d57

Browse files
649. Dota2 Senate
1 parent 18db2b6 commit 74c4d57

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

‎649. Dota2 Senate.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
fun predictPartyVictory(senate: String): String {
3+
val radiant = ArrayDeque<Int>()
4+
val dire = ArrayDeque<Int>()
5+
for ((index, char) in senate.withIndex()) {
6+
if (char == 'R') {
7+
radiant.add(index)
8+
} else {
9+
dire.add(index)
10+
}
11+
}
12+
13+
while (radiant.isNotEmpty() && dire.isNotEmpty()) {
14+
val radiantIndex = radiant.removeFirst()
15+
val direIndex = dire.removeFirst()
16+
if (radiantIndex < direIndex) {
17+
radiant.addLast(radiantIndex + senate.length)
18+
} else {
19+
dire.addLast(direIndex + senate.length)
20+
}
21+
}
22+
23+
return if (radiant.isNotEmpty()) "Radiant" else "Dire"
24+
}
25+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /