Skip to content

Commit 2c20320

Browse files
committed
Create 649. Dota2 参议院.js
1 parent 132d5f1 commit 2c20320

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Diff for: 649. Dota2 参议院.js

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

0 commit comments

Comments
 (0)