Advertisement
Guest User

jump.cpp

a guest
Sep 16th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. bool possible = false;
  2. int len;
  3. bool canJump(vector<int>& nums) {
  4. len = nums.size();
  5. if(len <= 1) return true;
  6. find(nums, len - 2, len - 1);
  7. return possible;
  8. }
  9.  
  10. void find(vector<int>& nums, int idx, int last){
  11. if(idx == 0) {
  12. if(idx + nums[idx] >= last) possible = true;
  13. return;
  14. }
  15. if(idx + nums[idx] >= last) {
  16. find(nums, idx - 1, idx);
  17. } else{
  18. find(nums, idx - 1, last);
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement