Update greedy_algorithms/jumpgame.cpp

Co-authored-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com>
This commit is contained in:
Rakshaa Viswanathan 2020-09-15 12:34:23 +05:30 committed by GitHub
parent 4aea8495d6
commit 5e30e7eb64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,7 +23,7 @@
* @param array of numbers containing the maximum jump (in steps) from that index * @param array of numbers containing the maximum jump (in steps) from that index
* @returns bool value whether final index can be reached or not * @returns bool value whether final index can be reached or not
*/ */
bool canJump(std::vector<int> nums) { bool canJump(const std::vector<int> &nums) {
auto lastPos = nums.size() - 1; auto lastPos = nums.size() - 1;
for (auto i = nums.size() - 1; i >= 0; i--) { for (auto i = nums.size() - 1; i >= 0; i--) {
if (i + nums[i] >= lastPos) { if (i + nums[i] >= lastPos) {