mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
添加(0649.Dota2参议院.md):增加typescript版本
This commit is contained in:
@ -244,6 +244,44 @@ var predictPartyVictory = function(senateStr) {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## TypeScript
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
function predictPartyVictory(senate: string): string {
|
||||||
|
// 数量差:Count(Radiant) - Count(Dire)
|
||||||
|
let deltaRDCnt: number = 0;
|
||||||
|
let hasR: boolean = true,
|
||||||
|
hasD: boolean = true;
|
||||||
|
const senateArr: string[] = senate.split('');
|
||||||
|
while (hasR && hasD) {
|
||||||
|
hasR = false;
|
||||||
|
hasD = false;
|
||||||
|
for (let i = 0, length = senateArr.length; i < length; i++) {
|
||||||
|
if (senateArr[i] === 'R') {
|
||||||
|
if (deltaRDCnt < 0) {
|
||||||
|
senateArr[i] = '';
|
||||||
|
} else {
|
||||||
|
hasR = true;
|
||||||
|
}
|
||||||
|
deltaRDCnt++;
|
||||||
|
} else if (senateArr[i] === 'D') {
|
||||||
|
if (deltaRDCnt > 0) {
|
||||||
|
senateArr[i] = '';
|
||||||
|
} else {
|
||||||
|
hasD = true;
|
||||||
|
}
|
||||||
|
deltaRDCnt--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hasR ? 'Radiant' : 'Dire';
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
|
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
|
||||||
|
Reference in New Issue
Block a user