Skip to content

Latest commit

 

History

History
30 lines (23 loc) · 577 Bytes

1089.Duplicate-Zeros.md

File metadata and controls

30 lines (23 loc) · 577 Bytes

1089. Duplicate Zeros

Difficulty: Easy

URL

https://leetcode.com/problems/duplicate-zeros/

Solution

Approach 1:

The code is shown below:

class Solution:
    def duplicateZeros(self, arr: List[int]) -> None:
        """
        Do not return anything, modify arr in-place instead.
        """
        i = 0
        while i < len(arr) - 1:
            if arr[i] != 0:
                i += 1
                continue
            for j in range(len(arr) - 1, i, -1):
                arr[j] = arr[j-1]
            arr[i+1] = 0
            i += 2