题解 | #青蛙跳跃#
青蛙跳跃
https://www.nowcoder.com/practice/290a76e0d54c4fa6951098c38781c50b
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param pond int整型一维数组 * @return int整型 */ public int minJump (int[] pond) { // write code here int length = pond.length; if (length == 1) return 0; int[]steps=new int[length]; Arrays.fill(steps,Integer.MAX_VALUE); steps[length -1] = 0; for(int i = length - 2;i>= 0;i--){ for(int j = Math.min(length - 1,i+pond[i]);j>i;j--){ steps[i] = Math.min(steps[i],steps[j]); } steps[i] ++; } return steps[0]; } }