/**
* Created by Seven_hu on 2015/9/21.
*/
/*
*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-ze Ro elements.
For example, given nums = [0, 1, 0, 3, and 1], after calling your function, Nums should is [3, 12, 0, 0,].
Note:
You must does this in-place without making a copy of the array.
Minimize The total number of operations.
Credits:
Special thanks to @jianchao. Li.fighter for adding the problem and creating all test cases.
*
*
* */
public class Solution {
public static void Main (string[] args) {
Int[] a={0,1,0,3,12};
Movezeroes (a);
for (int i=0;i<a.length;i++) {
System.out.print (a[i]+ "");
}
}
public static void Movezeroes (int[] nums) {
Count is used to record how many of the arrays are 0
int count=0;
for (int i=0;i<nums.length;i++) {
if (nums[i]==0) {
count=count+1;
}else{
Nums[i-count]=nums[i];
nums[i]=0;
}
}
}
}
Move 0 elements