LeetCode: Arrays 101: Inserting Items Into an Array
nuculabs.dev
Hello, Here are my solutions for the second part of the card: Arrays 101, from LeetCode. Duplicate Zeroes Given an array of integers, remove duplicate zeroes and shift the remaining elements. https://leetcode.com/problems/duplicate-zeros/ class Solution: def duplicateZeros(self, arr: List[int]) -> None: """ Do not return anything, modify arr in-place instead. """ index = 0 arr_length = len(arr) while index < arr_length: if arr[index] == 0: arr.insert(index, 0) arr.pop() index += 1 index += 1
LeetCode: Arrays 101: Inserting Items Into an Array
LeetCode: Arrays 101: Inserting Items Into an…
LeetCode: Arrays 101: Inserting Items Into an Array
Hello, Here are my solutions for the second part of the card: Arrays 101, from LeetCode. Duplicate Zeroes Given an array of integers, remove duplicate zeroes and shift the remaining elements. https://leetcode.com/problems/duplicate-zeros/ class Solution: def duplicateZeros(self, arr: List[int]) -> None: """ Do not return anything, modify arr in-place instead. """ index = 0 arr_length = len(arr) while index < arr_length: if arr[index] == 0: arr.insert(index, 0) arr.pop() index += 1 index += 1