MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / move_zeroes

Function move_zeroes

283-move-zeroes.rs:2–8  ·  view source on GitHub ↗

跟紧接着不为0的数字互换

(nums: &mut Vec<i32>)

Source from the content-addressed store, hash-verified

1// 跟紧接着不为0的数字互换
2pub fn move_zeroes(nums: &mut Vec<i32>) {
3 for i in 0..nums.len() {
4 for j in i..nums.len() {
5 if nums[i] == 0 && nums[j] != 0 { nums.swap(i, j) }
6 }
7 }
8}
9
10fn main() {
11 let mut nums = vec![1, 0, 0, 4, 3, 12];

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected