Two-pointers Summary
1.单序列
1.1 相向双指针
pair sum: two elements in a sorted array summing to a target
Palindrome Check
Reverse OperationsTrapping Water / max volume area: Compute water trapped between heights by moving pointers based on min height.
接雨水类问题,相当于在无序数组中,用双指针在o(n)时间复杂度条件下找到最大值。
1.2 同相双指针
1.3 原地修改
- 27. Remove Element
- 26. Remove Duplicates from Sorted Array
- 80. Remove Duplicates from Sorted Array II
- 75. Sort Colors
- 905. Sort Array By Parity
- 922. Sort Array By Parity II
- 1089. Duplicate Zeros
- 287. Find the Duplicate Number