1438. 绝对差不超过限制的最长连续子数组 https://leetcode.cn/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit
1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit https://leetcode.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit
862. 和至少为 K 的最短子数组 https://leetcode.cn/problems/shortest-subarray-with-sum-at-least-k
862. Shortest Subarray with Sum at Least K https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k
918. 环形子数组的最大和 https://leetcode.cn/problems/maximum-sum-circular-subarray
918. Maximum Sum Circular Subarray https://leetcode.com/problems/maximum-sum-circular-subarray
1696. 跳跃游戏 VI https://leetcode.cn/problems/jump-game-vi
1696. Jump Game VI https://leetcode.com/problems/jump-game-vi
1425. 带限制的子序列和 https://leetcode.cn/problems/constrained-subsequence-sum
1425. Constrained Subsequence Sum https://leetcode.com/problems/constrained-subsequence-sum
1429. 第一个唯一数字 https://leetcode.cn/problems/first-unique-number
1429. First Unique Number https://leetcode.com/problems/first-unique-number
Prerequisites
Before reading this article, you should learn:
First, I'll provide a general implementation of a monotonic queue structure. This involves Java generics, where E
represents any type. The Java Language Basics at the beginning of this site covers this, so I won't go into detail here.
E extends Comparable<E>
means that the type E
must implement the Comparable
interface, i.e., type E
is comparable, such as types like Integer, String
that implement the compareTo
method. The reason is straightforward: you need to find the maximum or minimum value in the queue, so the elements must be comparable.
Our original simple implementation included the max
method, which works by maintaining a queue maxq
at the backend. This queue ensures that elements from the tail to the head are monotonically increasing.