Leetcode每日一题:283.move-zeroes(移动零)

在这里插入图片描述

class Solution {
public:
    void moveZeroes(vector<int> &nums)
    {
        int len = nums.size();
        if (len < 2)
            return;
        int index = 0;
        for (int i = 0; i < len; i++)
        {
            if (nums[i] != 0)
                nums[index++] = nums[i];
        }
        while (index < len)
        {
            nums[index++] = 0;
        }
    }
};
func moveZeroes(nums []int) {
	len := len(nums)
	index := 0
	for i := 0; i < len; i++ {
		if nums[i] != 0 {
			nums[index] = nums[i]
			index++
		}
	}
	for index < len {
		nums[index] = 0
		index++
	}
}
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试 返回首页