O(n^2) solution is accepted. Shouldn't it get TLE for a medium level question?


  • 0
    K
    public class Solution {
        public int MinSubArrayLen(int s, int[] nums) {
            int sum = 0;
            int min = int.MaxValue;
            for (int i = 0; i < nums.Length - 1; i++){
                if (nums[i] >= s) return 1;
                sum = nums[i];
                for (int j = i + 1; j < nums.Length; j++){
                    sum += nums[j] ;
                    if (sum >= s){
                        min = Math.Min(min, j - i + 1);
                        break;
                    }
                }
            }
            return min == int.MaxValue ? 0 : min;
        }
    }
    

Log in to reply
 

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