Skip to content

Commit

Permalink
feat: add rust solution to lc problem: No.1823 (#3225)
Browse files Browse the repository at this point in the history
  • Loading branch information
K11E3R authored Jul 8, 2024
1 parent b9dc478 commit 6f425ec
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,20 @@ function findTheWinner(n: number, k: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn find_the_winner(n: i32, k: i32) -> i32 {
if n == 1 {
return 1;
}
let mut ans = (k + Solution::find_the_winner(n - 1, k)) % n;
return if ans == 0 { n } else { ans };
}
}
```

#### JavaScript

```js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,20 @@ function findTheWinner(n: number, k: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn find_the_winner(n: i32, k: i32) -> i32 {
if n == 1 {
return 1;
}
let mut ans = (k + Solution::find_the_winner(n - 1, k)) % n;
return if ans == 0 { n } else { ans };
}
}
```

#### JavaScript

```js
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
impl Solution {
pub fn find_the_winner(n: i32, k: i32) -> i32 {
if n == 1 {
return 1;
}
let mut ans = (k + Solution::find_the_winner(n - 1, k)) % n;
return if ans == 0 { n } else { ans };
}
}

0 comments on commit 6f425ec

Please sign in to comment.