代码随想录算法训练营第2天|数组Part02

给定一个含有 n 个正整数的数组和一个正整数 target

找出该数组中满足其总和大于等于 target 的长度最小的 子数组 [numsl, numsl+1, ..., numsr-1, numsr] ,并返回其长度。如果不存在符合条件的子数组,返回 0

  • 同样是双指针,滑动窗口是暴力解法的优化。
  • 通过 x === Infinityx === -Infinity 判断是否为无穷值。
  • 滑动窗口的时间复杂度:每个元素在滑动窗后进来操作一次,出去操作一次,所以时间复杂度是 2 × n 也就是O(n)。
阅读更多
Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×