/** Do not return anything, modify nums in-place instead. */ functionmoveZeroes(nums: number[]): void{ let leftIndex = 0; let rightIndex = nums.length - 1; while (leftIndex <= rightIndex) { if (nums[leftIndex] !== 0) { leftIndex++; continue; } nums.splice(leftIndex, 1); nums.push(0); rightIndex--; } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
impl Solution { pubfnmove_zeroes(nums: &mutVec<i32>) { letmut left = 0; letmut right = nums.len(); while left < right { if nums[left] == 0 { nums.splice(left..left + 1, []); nums.push(0); right = right - 1; } else { left = left + 1; } } } }