标签:
DP
public class Solution { public int jump(int[] A) { if (A == null || A.length == 0) { return 0; } int reach = 0; int lastreach = 0; int step = 0; for (int i = 0; i < A.length && i <= reach; i++) { if (i > lastreach) { step++; lastreach = reach; } reach = Math.max(reach, A[i] + i); } if (reach < A.length - 1) { return 0; } return step; } }
标签:
原文地址:http://www.cnblogs.com/77rousongpai/p/4534958.html