Skip to content

Commit 668c150

Browse files
authored
Create 649-dota2-senate.js
1 parent 30694a1 commit 668c150

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

649-dota2-senate.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @param {string} senate
3+
* @return {string}
4+
*/
5+
const predictPartyVictory = function (senate) {
6+
const m = senate.length,
7+
radiant = [],
8+
dire = []
9+
for (let i = 0; i < m; i++) {
10+
if (senate[i] === 'R') {
11+
radiant.push(i)
12+
} else {
13+
dire.push(i)
14+
}
15+
}
16+
17+
while (radiant.length && dire.length) {
18+
let r = radiant.shift(),
19+
d = dire.shift()
20+
if (r < d) {
21+
radiant.push(r + m)
22+
} else {
23+
dire.push(d + m)
24+
}
25+
}
26+
return radiant.length > dire.length ? 'Radiant' : 'Dire'
27+
}

0 commit comments

Comments
 (0)