和Jump Game思路差不多,都是DP,关键是要用一个数组maxNumbers[k]存储走k步的话,最远能够到达的序号,注意数组maxNumbers[]是递增的。
class Solution {
public:
const int MAXVALUE = 1 << 30;
int findMinStepToIndex(int maxNumbers[],int maxSteps,int index)
{
if (index == 0)
return 0;
int left = 1;
int right = maxSteps;
while (left < right)
{
int m = (left + right) / 2;
if (maxNumbers[m] < index)
{
left = m + 1;
}
else if (maxNumbers[m] > index......
阅读全文