File tree Expand file tree Collapse file tree 3 files changed +7
-4
lines changed
algorithms/dynamic_programming/min_path_sum Expand file tree Collapse file tree 3 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -52,4 +52,4 @@ grows quadratically.
5252
5353### Space Complexity
5454
55- The space complexity is O(n) since we only maintain a single working array ` dp ` with on entry per row.
55+ The space complexity is O(n) since we only maintain a single working array ` dp ` with one entry per row.
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ def min_path_sum_2(triangle: List[List[int]]) -> int:
4141 Complexity:
4242 Time Complexity results in O(n^2), since we visit every number in the triangle exactly once. For n rows, there are
4343 roughtl n^2/2 elements.
44- Space Complexity is O(1 ) since the triangle input array is updated in place
44+ Space Complexity is O(n ) since the triangle input array's last row is copied over
4545
4646 Args:
4747 triangle(list): A list of lists of integers representing the triangle
Original file line number Diff line number Diff line change 11import unittest
2+ import copy
23from typing import List
34from parameterized import parameterized
45from algorithms .dynamic_programming .min_path_sum import min_path_sum , min_path_sum_2
1516class MinPathSumInTriangleTestCase (unittest .TestCase ):
1617 @parameterized .expand (TEST_CASES )
1718 def test_min_path_sum_in_triangle (self , triangle : List [List [int ]], expected : int ):
18- actual = min_path_sum (triangle )
19+ input_triangle = copy .deepcopy (triangle )
20+ actual = min_path_sum (input_triangle )
1921 self .assertEqual (expected , actual )
2022
2123 @parameterized .expand (TEST_CASES )
2224 def test_min_path_sum_2_in_triangle (self , triangle : List [List [int ]], expected : int ):
23- actual = min_path_sum_2 (triangle )
25+ input_triangle = copy .deepcopy (triangle )
26+ actual = min_path_sum_2 (input_triangle )
2427 self .assertEqual (expected , actual )
2528
2629
You can’t perform that action at this time.
0 commit comments