Advertisement
YEZAELP

LeetCode: Jump Game II

Nov 1st, 2021 (edited)
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int dp[10010];
  4.     int jump(vector<int>& nums) {
  5.         int n = nums.size();
  6.         dp[0] = 0;
  7.         int pre = 0, cur = 1;
  8.         while(cur < n){
  9.             while(cur - pre > nums[pre])
  10.                 pre ++;
  11.             dp[cur] = dp[pre] + 1;
  12.             cur ++;
  13.         }
  14.         return dp[n-1];
  15.     }
  16. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement