You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (n == 2) { // if there are two houses, one with the maximum amount of money will be robbed
37
+
if (n == 2) { // if there are two houses, one with the maximum amount of
38
+
// money will be robbed
36
39
returnstd::max(money[0], money[1]);
37
40
}
38
41
int max_value = 0; // contains maximum stolen value at the end
@@ -58,28 +61,39 @@ static void test() {
58
61
// [1, 2, 3, 1] return 4
59
62
std::vector<int> array1 = {1, 2, 3, 1};
60
63
std::cout << "Test 1... ";
61
-
assert(dynamic_programming::house_robber::houseRobber(array1, array1.size()) == 4); // here the two non-adjacent houses that are robbed are first and third with total sum money as 4
4); // here the two non-adjacent houses that are robbed are first and
67
+
// third with total sum money as 4
62
68
std::cout << "passed" << std::endl;
63
69
64
70
// Test 2
65
71
// [6, 7, 1, 3, 8, 2, 4] return 19
66
72
std::vector<int> array2 = {6, 7, 1, 3, 8, 2, 4};
67
73
std::cout << "Test 2... ";
68
-
assert(dynamic_programming::house_robber::houseRobber(array2, array2.size()) == 19); // here the four non-adjacent houses that are robbed are first, third, fifth and seventh with total sum money as 19
0); // since there is no house no money can be robbed
76
87
std::cout << "passed" << std::endl;
77
88
78
89
// Test 4
79
90
// [2,7,9,3,1] return 12
80
91
std::vector<int> array4 = {2, 7, 9, 3, 1};
81
92
std::cout << "Test 4... ";
82
-
assert(dynamic_programming::house_robber::houseRobber(array4, array4.size()) == 12); // here the three non-adjacent houses that are robbed are first, third and fifth with total sum money as 12
0 commit comments