diff --git a/solution/1800-1899/1823.Find the Winner of the Circular Game/README.md b/solution/1800-1899/1823.Find the Winner of the Circular Game/README.md index 2233b825aaa05..7322f84c4eb10 100644 --- a/solution/1800-1899/1823.Find the Winner of the Circular Game/README.md +++ b/solution/1800-1899/1823.Find the Winner of the Circular Game/README.md @@ -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 diff --git a/solution/1800-1899/1823.Find the Winner of the Circular Game/README_EN.md b/solution/1800-1899/1823.Find the Winner of the Circular Game/README_EN.md index ae70a45fec097..ad18bcd253d10 100644 --- a/solution/1800-1899/1823.Find the Winner of the Circular Game/README_EN.md +++ b/solution/1800-1899/1823.Find the Winner of the Circular Game/README_EN.md @@ -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 diff --git a/solution/1800-1899/1823.Find the Winner of the Circular Game/Solution.rs b/solution/1800-1899/1823.Find the Winner of the Circular Game/Solution.rs new file mode 100644 index 0000000000000..1e5c3c839521c --- /dev/null +++ b/solution/1800-1899/1823.Find the Winner of the Circular Game/Solution.rs @@ -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 }; + } +}