1、双指针
- 维护区间信息、子序列匹配、利用序列有序性、单项链表找环
- 双指针 - OI Wiki (oi-wiki.org)
盛最多水的容器https://leetcode.cn/problems/container-with-most-water/
public class Solution {public int maxArea(int[] height) {int l = 0, r = height.length - 1;int ans = 0;while (l < r) {int area = Math.min(height[l], height[r]) * (r - l);ans = Math.max(ans, area);if (height[l] <= height[r]) {++l;}else {--r;}}return ans;}
}
2、前缀和
参见其他博客:特殊数组—前缀和解法