fix: pass index by reference and const it

This commit is contained in:
David Leal 2023-07-25 20:25:37 -06:00 committed by GitHub
parent 037b28b287
commit 4a3e7bbaec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,7 +40,7 @@ namespace greedy_algorithms {
* @returns false if the index can NOT be reached * @returns false if the index can NOT be reached
*/ */
template <typename T> template <typename T>
bool can_jump(const std::vector<T> &nums, int index = 1) { bool can_jump(const std::vector<T> &nums, const int &index = 1) {
const int size = nums.size() + 1 - nums[index]; const int size = nums.size() + 1 - nums[index];
if (nums[index] >= size) { // `>=` because the number can be higher than the size of the array. if (nums[index] >= size) { // `>=` because the number can be higher than the size of the array.
return true; return true;
@ -50,7 +50,7 @@ bool can_jump(const std::vector<T> &nums, int index = 1) {
} // namespace greedy_algorithms } // namespace greedy_algorithms
/** /**
* @brief Function to test above algorithm * @brief Function to test the above algorithm
* @returns void * @returns void
*/ */
static void test() { static void test() {