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
43
+
if (n == 2) { // if there are two houses, one with the maximum amount of
44
+
// money will be robbed
38
45
returnstd::max(money[0], money[1]);
39
46
}
40
47
uint32_t max_value = 0; // contains maximum stolen value at the end
@@ -60,28 +67,39 @@ static void test() {
60
67
// [1, 2, 3, 1] return 4
61
68
std::vector<uint32_t> array1 = {1, 2, 3, 1};
62
69
std::cout << "Test 1... ";
63
-
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
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
78
93
std::cout << "passed" << std::endl;
79
94
80
95
// Test 4
81
96
// [2,7,9,3,1] return 12
82
97
std::vector<uint32_t> array4 = {2, 7, 9, 3, 1};
83
98
std::cout << "Test 4... ";
84
-
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