-
Notifications
You must be signed in to change notification settings - Fork 0
/
1089.duplicate-zeros.py
59 lines (58 loc) · 1.29 KB
/
1089.duplicate-zeros.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#
# @lc app=leetcode.cn id=1089 lang=python3
#
# [1089] 删去字符串中的元音
#
# https://leetcode-cn.com/problems/duplicate-zeros/description/
#
# algorithms
# Easy (57.53%)
# Total Accepted: 13.7K
# Total Submissions: 23.9K
# Testcase Example: '[1,0,2,3,0,4,5,0]'
#
# 给你一个长度固定的整数数组 arr,请你将该数组中出现的每个零都复写一遍,并将其余的元素向右平移。
#
# 注意:请不要在超过该数组长度的位置写入元素。
#
# 要求:请对输入的数组 就地 进行上述修改,不要从函数返回任何东西。
#
#
#
# 示例 1:
#
# 输入:[1,0,2,3,0,4,5,0]
# 输出:null
# 解释:调用函数后,输入的数组将被修改为:[1,0,0,2,3,0,0,4]
#
#
# 示例 2:
#
# 输入:[1,2,3]
# 输出:null
# 解释:调用函数后,输入的数组将被修改为:[1,2,3]
#
#
#
#
# 提示:
#
#
# 1 <= arr.length <= 10000
# 0 <= arr[i] <= 9
#
#
#
class Solution:
def duplicateZeros(self, arr: List[int]) -> None:
"""
Do not return anything, modify arr in-place instead.
"""
ans = []
for i in arr:
if i != 0:
ans.append(i)
else:
ans += [0,0]
for i in range(len(arr)):
arr[i] = ans[i]