背向双指针
- Longest Palindromic Substring的中心线枚举算法
- Find K Closest Elements
相向双指针
两根指针一头一尾,向中间靠拢直到相遇: while left < right
time complexity: O(n)
- Reverse
- Recover rotated sorted array & rotate string(三步翻转法)
- Valid Palindrome
- follow up: 可以删掉一个字符的Valid Palindrome(证明题)
- Two Sum
- Partition
同向双指针
两根指针一前一后,直到前面的指针走过头
- Sliding Window
- Fast & Slow Pointers
time complexity: O(n)
- Move Zeros
Before solving the problem, you need to consider:
- Does the number of zeros matter?
- Should the result be in order or not?
- How to minimize the times of writing zeros in the array?