Skip to content

Commit cdd54cb

Browse files
hollowcrustpre-commit-ci[bot]
authored andcommitted
Add doctests, type hints; fix bug for dynamic_programming/minimum_partition.py (TheAlgorithms#10012)
* Add doctests, type hints; fix bug * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 920a8b5 commit cdd54cb

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

dynamic_programming/minimum_partition.py

+21-3
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,33 @@
33
"""
44

55

6-
def find_min(arr):
6+
def find_min(arr: list[int]) -> int:
7+
"""
8+
>>> find_min([1, 2, 3, 4, 5])
9+
1
10+
>>> find_min([5, 5, 5, 5, 5])
11+
5
12+
>>> find_min([5, 5, 5, 5])
13+
0
14+
>>> find_min([3])
15+
3
16+
>>> find_min([])
17+
0
18+
"""
719
n = len(arr)
820
s = sum(arr)
921

1022
dp = [[False for x in range(s + 1)] for y in range(n + 1)]
1123

12-
for i in range(1, n + 1):
24+
for i in range(n + 1):
1325
dp[i][0] = True
1426

1527
for i in range(1, s + 1):
1628
dp[0][i] = False
1729

1830
for i in range(1, n + 1):
1931
for j in range(1, s + 1):
20-
dp[i][j] = dp[i][j - 1]
32+
dp[i][j] = dp[i - 1][j]
2133

2234
if arr[i - 1] <= j:
2335
dp[i][j] = dp[i][j] or dp[i - 1][j - arr[i - 1]]
@@ -28,3 +40,9 @@ def find_min(arr):
2840
break
2941

3042
return diff
43+
44+
45+
if __name__ == "__main__":
46+
from doctest import testmod
47+
48+
testmod()

0 commit comments

Comments
 (0)