---
# System prepended metadata

title: 0283. Move Zeroes
tags: [Leetcode, Array, Easy]

---

# 0283. Move Zeroes
###### tags: `Leetcode` `Easy` `Array`
Link: https://leetcode-cn.com/problems/move-zeroes/
## 思路 $O(N)$ $O(1)$
双指针 一个遍历 一个指向下一个要放非零数字的位置，都遍历完之后，剩余的位置补0
## Code
```java=
class Solution {
    public void moveZeroes(int[] nums) {
        int nonZeroPos = 0;
        for(int i = 0;i < nums.length;i++){
            if(nums[i]!=0){
                nums[nonZeroPos++] = nums[i];
            }
        }
        for(int i = nonZeroPos;i < nums.length;i++){
            nums[i] = 0;
        }
    }
}
```
## Result
Your runtime beats **94.44 %** of java submissions.
Your memory usage beats **14.09 %** of java submissions.