From 1dd5b7c19a14a309145f89e15be4a74e1a27eb21 Mon Sep 17 00:00:00 2001 From: xiaolatiao <1628652790@qq.com> Date: Tue, 27 Jun 2023 20:14:37 +0800 Subject: [PATCH] feat: 2682 add rust solution Signed-off-by: xiaolatiao <1628652790@qq.com> --- .../README.md | 27 +++++++++++++++++++ .../README_EN.md | 27 +++++++++++++++++++ .../Solution.rs | 22 +++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 solution/2600-2699/2682.Find the Losers of the Circular Game/Solution.rs diff --git a/solution/2600-2699/2682.Find the Losers of the Circular Game/README.md b/solution/2600-2699/2682.Find the Losers of the Circular Game/README.md index f345ade6bd9ac..c4751bcdb1109 100644 --- a/solution/2600-2699/2682.Find the Losers of the Circular Game/README.md +++ b/solution/2600-2699/2682.Find the Losers of the Circular Game/README.md @@ -155,6 +155,33 @@ func circularGameLosers(n int, k int) (ans []int) { } ``` +### **Rust** + +```rust +impl Solution { + pub fn circular_game_losers(n: i32, k: i32) -> Vec { + let mut vis: Vec = vec![false; n as usize]; + + let mut i = 0; + let mut p = 1; + while !vis[i] { + vis[i] = true; + i = (i + p * k as usize) % n as usize; + p += 1; + } + + let mut ans = Vec::new(); + for i in 0..vis.len() { + if !vis[i] { + ans.push((i + 1) as i32); + } + } + + ans + } +} +``` + ### **...** ``` diff --git a/solution/2600-2699/2682.Find the Losers of the Circular Game/README_EN.md b/solution/2600-2699/2682.Find the Losers of the Circular Game/README_EN.md index 69f6575637692..9cdefcc8c0f1a 100644 --- a/solution/2600-2699/2682.Find the Losers of the Circular Game/README_EN.md +++ b/solution/2600-2699/2682.Find the Losers of the Circular Game/README_EN.md @@ -136,6 +136,33 @@ func circularGameLosers(n int, k int) (ans []int) { } ``` +### **Rust** + +```rust +impl Solution { + pub fn circular_game_losers(n: i32, k: i32) -> Vec { + let mut vis: Vec = vec![false; n as usize]; + + let mut i = 0; + let mut p = 1; + while !vis[i] { + vis[i] = true; + i = (i + p * k as usize) % n as usize; + p += 1; + } + + let mut ans = Vec::new(); + for i in 0..vis.len() { + if !vis[i] { + ans.push((i + 1) as i32); + } + } + + ans + } +} +``` + ### **...** ``` diff --git a/solution/2600-2699/2682.Find the Losers of the Circular Game/Solution.rs b/solution/2600-2699/2682.Find the Losers of the Circular Game/Solution.rs new file mode 100644 index 0000000000000..66fc9b3a7ad41 --- /dev/null +++ b/solution/2600-2699/2682.Find the Losers of the Circular Game/Solution.rs @@ -0,0 +1,22 @@ +impl Solution { + pub fn circular_game_losers(n: i32, k: i32) -> Vec { + let mut vis: Vec = vec![false; n as usize]; + + let mut i = 0; + let mut p = 1; + while !vis[i] { + vis[i] = true; + i = (i + p * k as usize) % n as usize; + p += 1; + } + + let mut ans = Vec::new(); + for i in 0..vis.len() { + if !vis[i] { + ans.push((i + 1) as i32); + } + } + + ans + } +} \ No newline at end of file