carloscn / structstudy

Leetcode daily trainning by using C/C++/RUST programming.
4 stars 1 forks source link

leetcode1089:复写零(duplicate-zeros) #185

Open carloscn opened 1 year ago

carloscn commented 1 year ago

问题描述

给你一个长度固定的整数数组 arr ,请你将该数组中出现的每个零都复写一遍,并将其余的元素向右平移。

注意:请不要在超过该数组长度的位置写入元素。请对输入的数组 就地 进行上述修改,不要从函数返回任何东西。

 

示例 1:

输入:arr = [1,0,2,3,0,4,5,0] 输出:[1,0,0,2,3,0,0,4] 解释:调用函数后,输入的数组将被修改为:[1,0,0,2,3,0,0,4] 示例 2:

输入:arr = [1,2,3] 输出:[1,2,3] 解释:调用函数后,输入的数组将被修改为:[1,2,3]  

提示:

1 <= arr.length <= 104 0 <= arr[i] <= 9

来源:力扣(LeetCode) 链接:https://leetcode.cn/problems/duplicate-zeros

carloscn commented 1 year ago

code

https://github.com/carloscn/structstudy/commit/130313028bc534263aedd41de4a6d96b7ae08289 https://review.gerrithub.io/c/carloscn/structstudy/+/552561