move zeros leetcode

Just use the thought of Bubble sort.

I think it would have an O(n) algriothm, I would try it later.

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


你可能感兴趣的:(leetcode,算法)