<commit_before>/**
 * Two Pointers
 */
class Solution {
public:
    int minSubArrayLen(int s, vector<int>& nums) {
        int n = nums.size(), start = 0, sum = 0, minlen = INT_MAX;
        for (int i = 0; i < n; i++) {
            sum += nums[i];
            while (sum >= s) {
                minlen = min(minlen, i - start + 1);
                sum -= nums[start++];
            }
        }
        return minlen == INT_MAX ? 0 : minlen;
    }
};<commit_msg>Update 209.cpp<commit_after>/*
 * Two Pointers
 * 
 */

// version 1: i as end, start as start
class Solution {
public:
    int minSubArrayLen(int s, vector<int>& nums) {
        int n = nums.size(), start = 0, sum = 0, minlen = INT_MAX;
        for (int i = 0; i < n; i++) {
            sum += nums[i];
            while (sum >= s) {
                minlen = min(minlen, i - start + 1);
                sum -= nums[start++];
            }
        }
        return minlen == INT_MAX ? 0 : minlen;
    }
};

// version 2: i as start, j as end
class Solution {
public:
    int minSubArrayLen(int s, vector<int>& nums) {    
        int i = 0, j = 0;
        int sum = 0, min_len = INT_MAX;
        for(; i < nums.size(); i++) {
            while(j < nums.size() && sum < s) {
                sum += nums[j];
                j++;
            }
            if(sum >= s) min_len = min(min_len, j - i);
            sum -= nums[i];
        }
        return min_len == INT_MAX ? 0 : min_len;
    }
};

// Conclusion:
// Can use a generic template to solve this kind of problems.
//



{'fraction_non_alphanumeric': 0.1509433962264151, 'fraction_numerical': 0.01236174365647365, 'mean_word_length': 1.4647435897435896, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5120215', 'n_tokens_mistral': 548, 'n_tokens_neox': 516, 'n_words': 159}