Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // problem link: https://leetcode.com/problems/jump-game-iii/
- class Solution {
- public:
- int dp[50004];
- int n = 0;
- int fun(vector<int>& arr, int i)
- {
- if(i>=n || i<0) return 0;
- if(arr[i]==0) return dp[i]=1;
- if(dp[i]!=-1) return dp[i];
- dp[i]=0; // test with commenting and not commenting this line
- return dp[i] = (fun(arr, i+arr[i]) | fun(arr,i-arr[i]));
- }
- bool canReach(vector<int>& arr, int start) {
- memset(dp,-1,sizeof(dp));
- n = arr.size();
- return fun(arr, start);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment