题解 | #几步可以从头跳到尾#
几步可以从头跳到尾
https://www.nowcoder.com/practice/de62bcee9f9a4881ac80cce6da42b135
using System;
using System.Collections.Generic;
class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 最少需要跳跃几次能跳到末尾
     * @param n int整型 数组A的长度
     * @param A int整型一维数组 数组A
     * @return int整型
     */
    public int Jump (int n, List<int> A) {
        // write code here
        if(A == null || A.Count == 0 || A.Count == 1)
        return 0;
        int nRtnMaxPos = 1;
        int nMinStep = 0;
        int nCurPos = 0;
        for(int nIndex = 0; nIndex < A.Count - 1; nIndex++){
            nRtnMaxPos = Math.Max(nIndex + A[nIndex], nRtnMaxPos);
            if(nCurPos == nIndex){
                nCurPos = nRtnMaxPos;
                nMinStep++;
            }
        }
        return nMinStep;
    }
}
 科大讯飞公司氛围 425人发布
科大讯飞公司氛围 425人发布 投递百度等公司10个岗位
投递百度等公司10个岗位 查看11道真题和解析
查看11道真题和解析