1.1 Two Pointers

6.1 同向双指针

• 快慢类

Linked List Cycle I, II

窗口类

6.1.1 窗口类sliding windows

minimum-size-subarray-sum

Minimum Window Substring

Longest Substring with At Most K Distinct Characters

3. Longest Substring Without Repeating Characters

438. Find All Anagrams in a String

\283. Move Zeroes

\1343. Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold

\1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit

\713. Subarray Product Less Than K

\1089. Duplicate Zeros

String Compressionarrow-up-right/Compress string in-place

• 6.2 相向双指针

\125. Valid Palindrome

\680. Valid Palindrome II

Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.

• 6.3 Two Sum

​ • 几乎所有 Two Sum 变种

哈希表(HashMap) vs 两根指针(Two Pointers)

对于求 2 个变量如何组合的问题

可以循环其中一个变量,然后研究另外一个变量如何变化

Two Sum III - Data structure design

\167. Two Sum II - Input array is sorted

\653. Two Sum IV - Input is a BST

Two Sum - Unique pairs

\15. 3Sum

\16. 3Sum Closest

\923. 3Sum With Multiplicity

\18. 4Sum

\454. 4Sum II

\611. Valid Triangle Number

Two Sum 计数问题

Two Sum <= target

O(1) 额外空间以及 O(nlogn) 时间复杂度

two sum >= target

6.4 Partition

​ • Quick Select • 分成两个部分 • 分成三个部分 • 一些你没听过的(但是面试会考的)排序算法

\561. Array Partition I

\905. Sort Array By Parity

Interleaving Positive and Negative Numbers

给出一个含有正整数和负整数的数组,重新排列成一个正负数交错的数组。

不需要保持正整数或者负整数原来的顺序。

Sort Letters by Case

Given a string which contains only letters. Sort it by lower case first and upper case second.

Sort Colors

分成三个部分:左中右

V1:两个循环,先分成左,中右;再分成中,右

V2: 统计各类别的个数(counting sort)【必须:可数】

V3:三分法 one-pass algorithm using only constant space

Rainbow Sort

Pancake Sort

Let given array be arr[] and size of array be n. 1) Start from current size equal to n and reduce current size by one while it’s greater than 1. Let the current size be curr_size. Do following for every curr_size ……a) Find index of the maximum element in arr[0..curr_szie-1]. Let the index be ‘mi’ ……b) Call flip(arr, mi) ……c) Call flip(arr, curr_size-1)

O(n) flip operations are performed in above code. The overall time complexity is O(n^2).

Sleep Sort

Time: O(n) space: O(n)

Spaghetti Sort

Time: O(n) space: O(n)

Bogo Sort

Random sort

6.5 Quick Select

\215. Kth Largest Element in an Array

Median

Given a unsorted array with integers, find the median of it.

A median is the middle number of the array after it is sorted.

If there are even numbers in the array, return the N/2-th number after sorted.

Last updated