From 17278293e4b179ba91054f8fe9f564932b9a6862 Mon Sep 17 00:00:00 2001 From: yassine naanani <27584700+K11E3R@users.noreply.github.com> Date: Mon, 8 Jul 2024 11:50:15 +0200 Subject: [PATCH 1/3] Solution 0ms Runtime 2.04 mb Memory space --- .../Solution.rs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 solution/1800-1899/1823.Find the Winner of the Circular Game/Solution.rs 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 }; + } +} From 3142012fd09196cf35b99dc69f466a4d5df913d4 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Mon, 8 Jul 2024 18:32:58 +0800 Subject: [PATCH 2/3] Update README.md --- .../README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 From 8487a85042c2e9c23fc450aa76097e5a62b230d5 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Mon, 8 Jul 2024 18:33:11 +0800 Subject: [PATCH 3/3] Update README_EN.md --- .../README_EN.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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