From 8f8e296c8086c5c07171b8e8a32645babc99ed54 Mon Sep 17 00:00:00 2001 From: "J. Alvarez" Date: Tue, 26 May 2020 22:53:21 -0500 Subject: [PATCH 1/2] Solved Challenge --- solutions/jcalvarezj/__init__.py | 0 solutions/jcalvarezj/solution.py | 14 ++++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 solutions/jcalvarezj/__init__.py create mode 100644 solutions/jcalvarezj/solution.py diff --git a/solutions/jcalvarezj/__init__.py b/solutions/jcalvarezj/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/solutions/jcalvarezj/solution.py b/solutions/jcalvarezj/solution.py new file mode 100644 index 0000000..5e47da8 --- /dev/null +++ b/solutions/jcalvarezj/solution.py @@ -0,0 +1,14 @@ +from typing import List + + +class Solution: + def duplicate_zeros(self, arr: List[int]): + initial_size = len(arr) + arr_enum = enumerate(arr.copy()) + acumulate = 0 + for i, num in arr_enum: + if num == 0: + arr.insert(i + acumulate + 1, 0) + acumulate += 1 + for i in range(len(arr) - initial_size): + arr.pop() \ No newline at end of file From 29f57ff65c321c4b8b2ec735fed163af0145536c Mon Sep 17 00:00:00 2001 From: "J. Alvarez" Date: Wed, 27 May 2020 00:00:38 -0500 Subject: [PATCH 2/2] Improved with pylint suggestions --- solutions/jcalvarezj/solution.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/solutions/jcalvarezj/solution.py b/solutions/jcalvarezj/solution.py index 5e47da8..7ee1744 100644 --- a/solutions/jcalvarezj/solution.py +++ b/solutions/jcalvarezj/solution.py @@ -1,8 +1,19 @@ +""" +This module includes my solution to the challenge +""" from typing import List class Solution: + """ + This class represents a solution object that provides methods used to + compute a result + """ def duplicate_zeros(self, arr: List[int]): + """ + This method duplicates the zeros inside the input array, while + respecting its original size + """ initial_size = len(arr) arr_enum = enumerate(arr.copy()) acumulate = 0 @@ -11,4 +22,4 @@ def duplicate_zeros(self, arr: List[int]): arr.insert(i + acumulate + 1, 0) acumulate += 1 for i in range(len(arr) - initial_size): - arr.pop() \ No newline at end of file + arr.pop()