https://leetcode.com/problems/minimum-size-subarray-sum/description/?envType=study-plan-v2&envId=top-interview-150

class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int n = nums.size();
        int ans = INT_MAX;
        int l = 0, r = 0;
        int cur = 0;
        while (r < n) {
            while (r < n && cur < target) {
                cur += nums[r];
                r += 1;
            }
            while (cur >= target) {
                ans = min(ans, r - l);
                cur -= nums[l];
                l += 1;
            }
        }
        return ans == INT_MAX ? 0 : ans;
    }
};

Time Complexity: O(n)
Space: O(1)

經典的 Two Pointer 題目,透過移動 L 以及 R 找到符合的 subarray 範圍