Skip to content

Commit 4a3e7bb

Browse files
authored
fix: pass index by reference and const it
1 parent 037b28b commit 4a3e7bb

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

greedy_algorithms/jump_game.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace greedy_algorithms {
4040
* @returns false if the index can NOT be reached
4141
*/
4242
template <typename T>
43-
bool can_jump(const std::vector<T> &nums, int index = 1) {
43+
bool can_jump(const std::vector<T> &nums, const int &index = 1) {
4444
const int size = nums.size() + 1 - nums[index];
4545
if (nums[index] >= size) { // `>=` because the number can be higher than the size of the array.
4646
return true;
@@ -50,7 +50,7 @@ bool can_jump(const std::vector<T> &nums, int index = 1) {
5050
} // namespace greedy_algorithms
5151

5252
/**
53-
* @brief Function to test above algorithm
53+
* @brief Function to test the above algorithm
5454
* @returns void
5555
*/
5656
static void test() {
@@ -71,7 +71,7 @@ static void test() {
7171
assert(greedy_algorithms::can_jump(nums) == false);
7272

7373
// 5th test
74-
nums = {7, 4, 8, 13, 2, 11};
74+
nums = { 7, 4, 8, 13, 2, 11 };
7575
assert(greedy_algorithms::can_jump(nums) == true);
7676

7777
std::cout << "All tests have successfully passed!\n";

0 commit comments

Comments
 (0)