Given a fixed length array
arr of integers, duplicate each occurrence of zero, shifting the remaining elements to the right.
Note that elements beyond the length of the original array are not written.
Do the above modifications to the input array in place, do not return anything from your function.
Input: [1,0,2,3,0,4,5,0] Output: null Explanation: After calling your function, the input array is modified to: [1,0,0,2,3,0,0,4]
Input: [1,2,3] Output: null Explanation: After calling your function, the input array is modified to: [1,2,3]
1 <= arr.length <= 10000
0 <= arr[i] <= 9
Use a temp array to store numbers in the new order.
class Solution: def duplicateZeros(self, arr: List[int]) -> None: """ Do not return anything, modify arr in-place instead. """ temp =  for num in arr: if num == 0: temp.append(0) temp.append(0) else: temp.append(num) for i in range(len(arr)): arr[i] = temp[i]
- Time Complexity: O(N)
- Space Complexity: O(N)