标签:log 选择 初始化 problem package font 操作 XML problems
package leetcode_50; /*** * * @author pengfei_zheng * 给定数组,找出最小跳动选择 */ public class Solution45 { public int jump(int[] nums) { if (nums == null || nums.length < 2) { return 0; } int left = 0; int right = nums[0]; int step = 1; while (left <= right) { if (right >= nums.length - 1) { return step; } int max = Integer.MIN_VALUE; for (; left <= right; left++) { max = Math.max(max, left + nums[left]); } if (max > right) { left = right; right = max; step++; } } return -1; } }
LeetCode 45 Jump Game II(按照数组进行移动)
标签:log 选择 初始化 problem package font 操作 XML problems
原文地址:http://www.cnblogs.com/zpfbuaa/p/6542150.html