File tree 3 files changed +100
-0
lines changed
solution/0600-0699/0649.Dota2 Senate
3 files changed +100
-0
lines changed Original file line number Diff line number Diff line change @@ -218,6 +218,41 @@ function predictPartyVictory(senate: string): string {
218
218
}
219
219
```
220
220
221
+ ### ** Rust**
222
+
223
+ ``` rust
224
+ impl Solution {
225
+ pub fn predict_party_victory (senate : String ) -> String {
226
+ let mut qr = std :: collections :: VecDeque :: new ();
227
+ let mut qd = std :: collections :: VecDeque :: new ();
228
+ let n = senate . len ();
229
+ for i in 0 .. n {
230
+ if let Some (char ) = senate . chars (). nth (i ) {
231
+ if char == 'R' {
232
+ qr . push_back (i );
233
+ } else {
234
+ qd . push_back (i );
235
+ }
236
+ }
237
+ }
238
+
239
+ while ! qr . is_empty () && ! qd . is_empty () {
240
+ let front_qr = qr . pop_front (). unwrap ();
241
+ let front_qd = qd . pop_front (). unwrap ();
242
+ if front_qr < front_qd {
243
+ qr . push_back (front_qr + n );
244
+ } else {
245
+ qd . push_back (front_qd + n );
246
+ }
247
+ }
248
+ if qr . is_empty () {
249
+ return " Dire" . to_string ();
250
+ }
251
+ " Radiant" . to_string ()
252
+ }
253
+ }
254
+ ```
255
+
221
256
### ** ...**
222
257
223
258
```
Original file line number Diff line number Diff line change @@ -197,6 +197,41 @@ function predictPartyVictory(senate: string): string {
197
197
}
198
198
```
199
199
200
+ ### ** Rust**
201
+
202
+ ``` rust
203
+ impl Solution {
204
+ pub fn predict_party_victory (senate : String ) -> String {
205
+ let mut qr = std :: collections :: VecDeque :: new ();
206
+ let mut qd = std :: collections :: VecDeque :: new ();
207
+ let n = senate . len ();
208
+ for i in 0 .. n {
209
+ if let Some (char ) = senate . chars (). nth (i ) {
210
+ if char == 'R' {
211
+ qr . push_back (i );
212
+ } else {
213
+ qd . push_back (i );
214
+ }
215
+ }
216
+ }
217
+
218
+ while ! qr . is_empty () && ! qd . is_empty () {
219
+ let front_qr = qr . pop_front (). unwrap ();
220
+ let front_qd = qd . pop_front (). unwrap ();
221
+ if front_qr < front_qd {
222
+ qr . push_back (front_qr + n );
223
+ } else {
224
+ qd . push_back (front_qd + n );
225
+ }
226
+ }
227
+ if qr . is_empty () {
228
+ return " Dire" . to_string ();
229
+ }
230
+ " Radiant" . to_string ()
231
+ }
232
+ }
233
+ ```
234
+
200
235
### ** ...**
201
236
202
237
```
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn predict_party_victory ( senate : String ) -> String {
3
+ let mut qr = std:: collections:: VecDeque :: new ( ) ;
4
+ let mut qd = std:: collections:: VecDeque :: new ( ) ;
5
+ let n = senate. len ( ) ;
6
+ for i in 0 ..n {
7
+ if let Some ( char) = senate. chars ( ) . nth ( i) {
8
+ if char == 'R' {
9
+ qr. push_back ( i) ;
10
+ } else {
11
+ qd. push_back ( i) ;
12
+ }
13
+ }
14
+ }
15
+
16
+ while !qr. is_empty ( ) && !qd. is_empty ( ) {
17
+ let front_qr = qr. pop_front ( ) . unwrap ( ) ;
18
+ let front_qd = qd. pop_front ( ) . unwrap ( ) ;
19
+ if front_qr < front_qd {
20
+ qr. push_back ( front_qr + n) ;
21
+ } else {
22
+ qd. push_back ( front_qd + n) ;
23
+ }
24
+ }
25
+ if qr. is_empty ( ) {
26
+ return "Dire" . to_string ( ) ;
27
+ }
28
+ "Radiant" . to_string ( )
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments