leetcode Move Zeroes

来源:互联网 发布:淘宝打折工具有什么用 编辑:程序博客网 时间:2024/06/02 23:48

题目链接

public class Solution {    public void moveZeroes(int[] nums) {        int moveStep=0;        int i=0;        for(i=0;i<nums.length;i++)        {            if(nums[i]!=0)            {                nums[i-moveStep]=nums[i];            }            else            {                moveStep++;            }        }        for(int k=nums.length-moveStep;k<nums.length;k++)        {            nums[k]=0;        }    }}
0 0
原创粉丝点击