From 83de8ac2a1e3f6203f25e5b792acb22bc187676d Mon Sep 17 00:00:00 2001 From: "junjie2.luo" Date: Thu, 10 Oct 2024 17:25:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=200283.=E7=A7=BB=E5=8A=A8=E9=9B=B6,?= =?UTF-8?q?=E6=96=B0=E5=A2=9Erust=E8=A7=A3=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0283.移动零.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/problems/0283.移动零.md b/problems/0283.移动零.md index 4d8fd9a1..cbce0295 100644 --- a/problems/0283.移动零.md +++ b/problems/0283.移动零.md @@ -169,7 +169,20 @@ void moveZeroes(int* nums, int numsSize){ } ``` - +### Rust +```rust +impl Solution { + pub fn move_zeroes(nums: &mut Vec) { + let mut slow = 0; + for fast in 0..nums.len() { + if nums[fast] != 0 { + nums.swap(slow, fast); + slow += 1; + } + } + } +} +```