# 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++;
}
}
}
}
}

## <LeetCode OJ> 283. Move Zeroes

283. Move Zeroes My Submissions Question Total Accepted: 40008 Total Submissions: 94323 Difficul...

## 【LeetCode-283】Move Zeroes

Move Zeroes Given an array nums, write a function to move all 0's to the end of it while mainta...

## LeetCode 283 Move Zeroes（移动所有的零元素）

• NoMasp
• 2015年12月26日 19:07
• 4134

## （数组）leetcode 283：Move Zeroes

（数组）leetcode 283：Move Zeroes

## leetcode-283. Move Zeroes c语言

1、来源：点击打开链接 2、题目： Given an array nums, write a function to move all 0's to the end of it while ma...
• tzh476
• 2016年07月20日 07:49
• 279

## [Leetcode 283]Move Zeroes

举报原因： 您举报文章：leetcode：283. Move Zeroes（Java）解答 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)