import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @param target int整型 * @return int整型 */ public int minSubarray (int[] nums, int target) { // write code here // 解题思路:双指针,滑动窗口方法 int l = 0; int r = 0; int sum = 0; int length = Integer.MAX_VALUE; while (r < nums.length) { while (r < nums.length && sum < target) { sum += nums[r]; r++; } while (l < r && sum >= target) { length = Math.min(length, r - l); sum = sum - nums[l]; l++; } } return length; } }