###### leetcode：283. Move Zeroes（Java）解答

Move Zeroes

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.

For example, given nums = [0, 1, 0, 3, 12], after calling your function, nums should be [1, 3, 12, 0, 0].

Note:
You must do this in-place without making a copy of the array.
Minimize the total number of operations.

public class Solution {
public void moveZeroes(int[] nums) {
if (nums != null) {
int length = nums.length;
for (int i = 0, j = 0; i < length; i++) {
if (nums[i] != 0) {
if (i != j) {
nums[j] = nums[i];
nums[i] = 0;
}
j++;
}
}
}
}
}

#### Java学习指南系列（Java快速入门）

2017年08月09日 15:30

#### 【leetcode】283. Move Zeros

2015-09-21 11:29:17

#### leetcode 283: Move Zeroes

2015-09-19 13:32:31

#### LeetCode 283. Move Zeros 解题报告

2016-09-21 15:44:32

#### leetcode283

2015-09-24 15:41:55

#### [leetcode-283]Move Zeroes(java)

2015-09-24 20:57:26

#### [LeetCode 283] Move Zeroes

2015-09-24 07:19:32

#### leetcode 283 move zeroes -java

2015-12-11 10:58:55

#### leetcode：Move Zeroes 【Java】

2016-03-17 19:59:55

#### LeetCode283——Move Zeroes我的解法

2015-09-19 10:07:42

## 不良信息举报

leetcode：283. Move Zeroes（Java）解答