From a44ac2c51f16be461944007f1f55cad84a63e891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=E1=BB=93=20V=C4=83n=20H=C3=B2a?= <56647826+hovanhoa@users.noreply.github.com> Date: Wed, 10 Apr 2024 16:53:16 +0700 Subject: [PATCH] Time: 43 ms (61.16%), Space: 11.9 MB (68.01%) - LeetHub --- 1089-duplicate-zeros/1089-duplicate-zeros.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 1089-duplicate-zeros/1089-duplicate-zeros.py diff --git a/1089-duplicate-zeros/1089-duplicate-zeros.py b/1089-duplicate-zeros/1089-duplicate-zeros.py new file mode 100644 index 0000000..132cb14 --- /dev/null +++ b/1089-duplicate-zeros/1089-duplicate-zeros.py @@ -0,0 +1,14 @@ +class Solution(object): + def duplicateZeros(self, arr): + """ + :type arr: List[int] + :rtype: None Do not return anything, modify arr in-place instead. + """ + i = 0 + while i < len(arr): + if arr[i] == 0: + arr.insert(i+1, 0) + arr.pop() + i += 1 + i += 1 + return arr \ No newline at end of file