From 759313d0ce67552d89db89fcdec3c44d7af5a6e2 Mon Sep 17 00:00:00 2001 From: Rakshaa Viswanathan <46165429+rakshaa2000@users.noreply.github.com> Date: Fri, 4 Sep 2020 11:16:15 +0530 Subject: [PATCH] documentation added, testing yet to be added --- greedy_algorithms/jumpgame.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/greedy_algorithms/jumpgame.cpp b/greedy_algorithms/jumpgame.cpp index 6f7a2dd18..b3d2c4420 100644 --- a/greedy_algorithms/jumpgame.cpp +++ b/greedy_algorithms/jumpgame.cpp @@ -6,10 +6,6 @@ * This solution takes in input as a vector and output as a boolean to check if you can reach the last position. * @author [Rakshaa Viswanathan](https://github.com/rakshaa2000) */ -//Jump Game: -/*Given an array of non-negative integers, you are initially positioned at the first index of the array. -Each element in the array represents your maximum jump length at that position. -Determine if you are able to reach the last index.*/ #include #include @@ -22,6 +18,11 @@ Determine if you are able to reach the last index.*/ *If yes, then that is the last position you can reach starting from the back. *After the end of the loop, if we reach the lastPos as 0, then the destination can be reached from the start position. */ + /** + * This function implements the above algorithm + * @param vector of nums containing the maximum jump (in steps) from that index + * @return returns bool value whether final index can be reached or not + */ bool canJump(std::vector nums) { auto lastPos = nums.size() - 1; for (auto i = nums.size() - 1; i >= 0; i--) {