[LeetCode] Duplicate Zeros (Python)

2024. 2. 27. 10:41자료구조

 

 

class Solution:
    def duplicateZeros(self, arr: List[int]) -> None:
        
        temp = []
        for i in range(len(arr)):
            if arr[i] == 0:
                temp.append(arr[i])
            temp.append(arr[i])
        
        answer = temp[:len(arr)]
        
        for i in range(len(arr)):
            arr[i] = answer[i]