Leetcode

Leetcode 209. Minimum Size Subar

2018-12-12  本文已影响1人  SnailTyan

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Minimum Size Subarray Sum

2. Solution

class Solution {
public:
    int minSubArrayLen(int s, vector<int>& nums) {
        int index = 0;
        int minimum = INT_MAX;
        for(int i = 0; i < nums.size(); i++) {
            s = s - nums[i];
            while(s <= 0) {
                minimum = min(minimum, i - index + 1);
                s += nums[index++];
            }
        }
        if(minimum == INT_MAX) {
            return 0;
        }
        return minimum;
    }
};

Reference

  1. https://leetcode.com/problems/minimum-size-subarray-sum/description/
上一篇下一篇

猜你喜欢

热点阅读