和I一样的...
只是把bool数组改成int数组,记录下次数就好了...
不过为毛是最优我还没有证明...意识流吧...
class Solution { public: int jump(int A[], int n) { vector<int> f(n , 0); int maxi = 0; for(int i = 0 ; i < n ; i++){ if(f[i] > 0 || i == 0){ if(i + A[i] > maxi){ for(int j = maxi + 1 ; j <= i + A[i]&& j<n; j++){ f[j] = f[i] + 1; } maxi = i + A[i]; } } } return f[n - 1]; } };
by 1957