请问为什么for中嵌套while循环 时间复杂度却还是O(n)呢
论文问答
1
class Solution {
public int minSubArrayLen(int target, int[] nums) {
int left = 0;
int result = Integer.MAX_VALUE;
int sum = 0;
for(int right = 0; right < nums.length; right++){
sum += nums[right];
while(sum >= target){
result = Math.min(result, (right - left + 1));
sum -= nums[left++];
}
}
return result == Integer.MAX_VALUE ? 0 : result;
}
}
java ```
发表回复