move zeros leetcode

来源:互联网 发布:网络剧如何赚钱 编辑:程序博客网 时间:2024/04/27 14:09

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


0 0
原创粉丝点击