Skip to content

Commit ef1f008

Browse files
github-actionsgithub-actions
authored andcommitted
clang-format and clang-tidy fixes for 6b0bea9
1 parent 6b0bea9 commit ef1f008

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

dynamic_programming/house_robber.cpp

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
/**
22
* @file
3-
* @brief Implementation of [House Robber Problem](https://labuladong.gitbook.io/algo-en/i.-dynamic-programming/houserobber) algorithm
3+
* @brief Implementation of [House Robber
4+
* Problem](https://labuladong.gitbook.io/algo-en/i.-dynamic-programming/houserobber)
5+
* algorithm
46
* @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.
7+
* Solution of House robber problem uses a dynamic programming concept that
8+
* works in \f$O(n)\f$ time and works in \f$O(1)\f$ space.
69
* @author [Swastika Gupta](https://github.com/Swastyy)
710
*/
811

@@ -17,24 +20,28 @@
1720
namespace dynamic_programming {
1821
/**
1922
* @namespace house_robber
20-
* @brief Functions for the [House Robber](https://labuladong.gitbook.io/algo-en/i.-dynamic-programming/houserobber)
23+
* @brief Functions for the [House
24+
* Robber](https://labuladong.gitbook.io/algo-en/i.-dynamic-programming/houserobber)
2125
* algorithm
2226
*/
2327
namespace house_robber {
2428
/**
25-
* @brief The main function implements house robber algorithm using dynamic programming
29+
* @brief The main function implements house robber algorithm using dynamic
30+
* programming
2631
* @param money array containing money in the ith house
2732
* @param n size of array
2833
* @returns maximum amount of money that can be robbed
2934
*/
30-
std::uint32_t houseRobber(const std::vector<uint32_t> &money, const uint32_t &n) {
35+
std::uint32_t houseRobber(const std::vector<uint32_t> &money,
36+
const uint32_t &n) {
3137
if (n == 0) { // if there is no house
3238
return 0;
3339
}
3440
if (n == 1) { // if there is only one house
3541
return money[0];
3642
}
37-
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
3845
return std::max(money[0], money[1]);
3946
}
4047
uint32_t max_value = 0; // contains maximum stolen value at the end
@@ -60,28 +67,39 @@ static void test() {
6067
// [1, 2, 3, 1] return 4
6168
std::vector<uint32_t> array1 = {1, 2, 3, 1};
6269
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
70+
assert(
71+
dynamic_programming::house_robber::houseRobber(array1, array1.size()) ==
72+
4); // here the two non-adjacent houses that are robbed are first and
73+
// third with total sum money as 4
6474
std::cout << "passed" << std::endl;
6575

6676
// Test 2
6777
// [6, 7, 1, 3, 8, 2, 4] return 19
6878
std::vector<uint32_t> array2 = {6, 7, 1, 3, 8, 2, 4};
6979
std::cout << "Test 2... ";
70-
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
80+
assert(
81+
dynamic_programming::house_robber::houseRobber(array2, array2.size()) ==
82+
19); // here the four non-adjacent houses that are robbed are first,
83+
// third, fifth and seventh with total sum money as 19
7184
std::cout << "passed" << std::endl;
7285

7386
// Test 3
7487
// [] return 0
7588
std::vector<uint32_t> array3 = {};
7689
std::cout << "Test 3... ";
77-
assert(dynamic_programming::house_robber::houseRobber(array3, array3.size()) == 0); // since there is no house no money can be robbed
90+
assert(
91+
dynamic_programming::house_robber::houseRobber(array3, array3.size()) ==
92+
0); // since there is no house no money can be robbed
7893
std::cout << "passed" << std::endl;
7994

8095
// Test 4
8196
// [2,7,9,3,1] return 12
8297
std::vector<uint32_t> array4 = {2, 7, 9, 3, 1};
8398
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
99+
assert(
100+
dynamic_programming::house_robber::houseRobber(array4, array4.size()) ==
101+
12); // here the three non-adjacent houses that are robbed are first,
102+
// third and fifth with total sum money as 12
85103
std::cout << "passed" << std::endl;
86104
}
87105

0 commit comments

Comments
 (0)