Please add test case


  • 0
    A

    The following codes got AC but it will fail at a test case with s = INT_MAX

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

  • 0

    Could you please give a test case of nums and s = INT_MAX where your code will fail? Thanks.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.