java.lang.Object
g0201_0300.s0209_minimum_size_subarray_sum.Solution

public class Solution extends Object
209 - Minimum Size Subarray Sum.<p>Medium</p> <p>Given an array of positive integers <code>nums</code> and a positive integer <code>target</code>, return the minimal length of a <strong>contiguous subarray</strong> <code>[nums<sub>l</sub>, nums<sub>l+1</sub>, &hellip;, nums<sub>r-1</sub>, nums<sub>r</sub>]</code> of which the sum is greater than or equal to <code>target</code>. If there is no such subarray, return <code>0</code> instead.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> target = 7, nums = [2,3,1,2,4,3]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> The subarray [4,3] has the minimal length under the problem constraint.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> target = 4, nums = [1,4,4]</p> <p><strong>Output:</strong> 1</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> target = 11, nums = [1,1,1,1,1,1,1,1]</p> <p><strong>Output:</strong> 0</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= target <= 10<sup>9</sup></code></li> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>1 <= nums[i] <= 10<sup>5</sup></code></li> </ul> <p><strong>Follow up:</strong> If you have figured out the <code>O(n)</code> solution, try coding another solution of which the time complexity is <code>O(n log(n))</code>.</p>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minSubArrayLen

      public int minSubArrayLen(int target, int[] nums)