Advertisement
YEZAELP

LeetCode: Jump Game II

Nov 1st, 2021 (edited)
162
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data Copied
Advertisement