* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* 最少需要跳跃几次能跳到末尾
* @param n int整型 数组A的长度
* @param A int整型一维数组 数组A
* @return int整型
*/
function Jump(n, A) {
// write code here
let res = 0
let end = 0
let max = 0
for (let i = 0; i < n-1; i++) {
max = Math.max(max, A[i] + i)
if (i == end) {
end = max
res++
}
}
return res
}
module.exports = {
Jump : Jump
};