LeetCode[209] 长度最小的子数组

Related Topics:
“数组”: https://leetcode.com/tag/array/
“二分查找”: https://leetcode.com/tag/binary-search/
“前缀和”: https://leetcode.com/tag/prefix-sum/
“滑动窗口”: https://leetcode.com/tag/sliding-window/
Similar Questions:
“最小覆盖子串”: https://leetcode.com/problems/minimum-window-substring/
“和等于 k 的最长子数组长度”: https://leetcode.com/problems/maximum-size-subarray-sum-equals-k/
“最长重复子数组”: https://leetcode.com/problems/maximum-length-of-repeated-subarray/

Problem:

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

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

示例 1:

1
2
3
输入:target = 7, nums = [2,3,1,2,4,3]
输出:2
解释:子数组 [4,3] 是该条件下的长度最小的子数组。

示例 2:

1
2
输入:target = 4, nums = [1,4,4]
输出:1

示例 3:

1
2
输入:target = 11, nums = [1,1,1,1,1,1,1,1]
输出:0

提示:

  • 1 <= target <= 109
  • 1 <= nums.length <= 105
  • 1 <= nums[i] <= 105

进阶:

  • 如果你已经实现O(n) 时间复杂度的解法, 请尝试设计一个 O(n log(n)) 时间复杂度的解法。[
Read more

LeetCode[718] 最长重复子数组

“数组”: https://leetcode.com/tag/array/
“哈希表”: https://leetcode.com/tag/hash-table/
“二分查找”: https://leetcode.com/tag/binary-search/
“动态规划”: https://leetcode.com/tag/dynamic-programming/
Similar Questions:
“长度最小的子数组”: https://leetcode.com/problems/minimum-size-subarray-sum/

Problem:

给两个整数数组 AB ,返回两个数组中公共的、长度最长的子数组的长度。

示例:

1
2
3
4
5
6
输入:
A: [1,2,3,2,1]
B: [3,2,1,4,7]
输出:3
解释:
长度最长的公共子数组是 [3, 2, 1] 。

提示:

  • 1 <= len(A), len(B) <= 1000
  • 0 <= A[i], B[i] < 100
Read more