Skip to content

Commit 6f425ec

Browse files
authored
feat: add rust solution to lc problem: No.1823 (doocs#3225)
1 parent b9dc478 commit 6f425ec

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

solution/1800-1899/1823.Find the Winner of the Circular Game/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,20 @@ function findTheWinner(n: number, k: number): number {
149149
}
150150
```
151151

152+
#### Rust
153+
154+
```rust
155+
impl Solution {
156+
pub fn find_the_winner(n: i32, k: i32) -> i32 {
157+
if n == 1 {
158+
return 1;
159+
}
160+
let mut ans = (k + Solution::find_the_winner(n - 1, k)) % n;
161+
return if ans == 0 { n } else { ans };
162+
}
163+
}
164+
```
165+
152166
#### JavaScript
153167

154168
```js

solution/1800-1899/1823.Find the Winner of the Circular Game/README_EN.md

+14
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,20 @@ function findTheWinner(n: number, k: number): number {
148148
}
149149
```
150150

151+
#### Rust
152+
153+
```rust
154+
impl Solution {
155+
pub fn find_the_winner(n: i32, k: i32) -> i32 {
156+
if n == 1 {
157+
return 1;
158+
}
159+
let mut ans = (k + Solution::find_the_winner(n - 1, k)) % n;
160+
return if ans == 0 { n } else { ans };
161+
}
162+
}
163+
```
164+
151165
#### JavaScript
152166

153167
```js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
impl Solution {
2+
pub fn find_the_winner(n: i32, k: i32) -> i32 {
3+
if n == 1 {
4+
return 1;
5+
}
6+
let mut ans = (k + Solution::find_the_winner(n - 1, k)) % n;
7+
return if ans == 0 { n } else { ans };
8+
}
9+
}

0 commit comments

Comments
 (0)