My solution times out.


  • 0
    M

    Here is my solution below. Somehow it times out but I don't know why. Any idea?

    public class Solution {
        public int minSubArrayLen(int s, int[] nums) {
            int ans = Integer.MAX_VALUE;
            int sum = 0;
            int left = 0;
            for (int i = 0; i < nums.length; i++)
                sum += nums[i];
                while (sum >= s)
                    ans = Math.min(ans, i - left + 1);
                    sum -= nums[left++];
            if (ans == Integer.MAX_VALUE) return 0;
            else return ans;
        }
    }
    

Log in to reply
 

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