题解 | #移动 0#

移动 0

https://www.nowcoder.com/practice/102586387caa4afcbad6f96affce9780

import java.util.*;


public class Solution {

    public int[] moveZeroes (int[] nums) {
        // write code here
        int[] ret = new int[nums.length];
        int i = 0;
        int j = 0;
        while(i < nums.length){
            while(i < nums.length && nums[i] == 0){
                i++;
            }
            if (i == nums.length){
                break;
            }
            ret[j++] = nums[i++];
        }

        return ret;
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务