Explore - LeetCode
LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore.
leetcode.com
Problem
Given a fixed-length integer array arr, duplicate each occurrence of zero, shifting the remaining elements to the right.
solution
class Solution:
def duplicateZeros(self, arr: List[int]) -> None:
"""
Do not return anything, modify arr in-place instead.
"""
temp = []
N = len(arr)
for i in arr:
if i ==0:
temp.append(i)
temp.append(i)
answer = temp[:N]
for i in range(N):
arr[i] = answer[i]
'알고리즘 > 기타 알고리즘' 카테고리의 다른 글
[LeetCode] Merge Sorted Array (Python) (0) | 2022.05.22 |
---|---|
[LeetCode] Squares of a Sorted Array (Python) (0) | 2022.05.16 |
[LeetCode] Find Numbers with Even Number of Digits (Python) (0) | 2022.05.16 |
[LeetCode] Max Consecutive Ones (Python) (0) | 2022.05.16 |
[이것이 코딩 테스트다 with Python] 고정점 찾기 : 이진탐색 (0) | 2022.01.24 |