Skip to content

Commit d364d13

Browse files
github-actionsgithub-actions
authored andcommitted
clang-format and clang-tidy fixes for 39c3719
1 parent 39c3719 commit d364d13

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

dynamic_programming/house_robber.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
* @file
33
* @brief Implementation of [House Robber Problem] algorithm
44
* @details
5-
* Solution of House robber problem uses a dynamic programming concept that works in \f$O(n)\f$ time and works in \f$O(1)\f$ space.
5+
* Solution of House robber problem uses a dynamic programming concept that
6+
* works in \f$O(n)\f$ time and works in \f$O(1)\f$ space.
67
*/
78

89
#include <cassert> /// for assert
@@ -20,7 +21,8 @@ namespace dynamic_programming {
2021
*/
2122
namespace house_robber {
2223
/**
23-
* @brief The main function implements house robber algorithm using dynamic programming
24+
* @brief The main function implements house robber algorithm using dynamic
25+
* programming
2426
* @param money array containing money in the ith house
2527
* @param n size of array
2628
* @returns maximum amount of money that can be robbed
@@ -32,7 +34,8 @@ std::uint64_t houseRobber(const std::vector<int> &money, int n) {
3234
if (n == 1) { // if there is only one house
3335
return money[0];
3436
}
35-
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
3639
return std::max(money[0], money[1]);
3740
}
3841
int max_value = 0; // contains maximum stolen value at the end
@@ -58,28 +61,39 @@ static void test() {
5861
// [1, 2, 3, 1] return 4
5962
std::vector<int> array1 = {1, 2, 3, 1};
6063
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
64+
assert(
65+
dynamic_programming::house_robber::houseRobber(array1, array1.size()) ==
66+
4); // here the two non-adjacent houses that are robbed are first and
67+
// third with total sum money as 4
6268
std::cout << "passed" << std::endl;
6369

6470
// Test 2
6571
// [6, 7, 1, 3, 8, 2, 4] return 19
6672
std::vector<int> array2 = {6, 7, 1, 3, 8, 2, 4};
6773
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
74+
assert(
75+
dynamic_programming::house_robber::houseRobber(array2, array2.size()) ==
76+
19); // here the four non-adjacent houses that are robbed are first,
77+
// third, fifth and seventh with total sum money as 19
6978
std::cout << "passed" << std::endl;
70-
79+
7180
// Test 3
7281
// [] return 0
7382
std::vector<int> array3 = {};
7483
std::cout << "Test 3... ";
75-
assert(dynamic_programming::house_robber::houseRobber(array3, array3.size()) == 0); // since there is no house no money can be robbed
84+
assert(
85+
dynamic_programming::house_robber::houseRobber(array3, array3.size()) ==
86+
0); // since there is no house no money can be robbed
7687
std::cout << "passed" << std::endl;
7788

7889
// Test 4
7990
// [2,7,9,3,1] return 12
8091
std::vector<int> array4 = {2, 7, 9, 3, 1};
8192
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
93+
assert(
94+
dynamic_programming::house_robber::houseRobber(array4, array4.size()) ==
95+
12); // here the three non-adjacent houses that are robbed are first,
96+
// third and fifth with total sum money as 12
8397
std::cout << "passed" << std::endl;
8498
}
8599

0 commit comments

Comments
 (0)