283. Move Zeroes 移動零
❀ Origin
Problem
Given an array nums
,
write a function to move all 0
‘s to the end of it while maintaining the relative order of the non-zero elements.
Note
- You must do this in-place without making a copy of the array.
- Minimize the total number of operations.
Example
1 | Input: [0,1,0,3,12] |
❀ 翻譯
問題
給定一個陣列 nums
,
寫一個函數去移動所有的 0
到最後面, 且過程中保持非零元素的相對順序.
注意
- 你必須在不製作一個複製陣列的情況下, 就以此操作.
- 最小化所有的操作數.
❀ Solution
JavaScript
1 | /** |
JavaScript II
1 | /** |
Golang
1 |
|
Golang II
1 |
|