链接:https://zhuanlan.zhihu.com/p/161036474
开篇的话:LeetCode题目太多,且其中的基本知识点其实是变化不大的,因此全部刷完肯定不是最好最有效的方式。短时间刷不完也记不住。所以要刷经典题,要刷一题掌握一个类型,遇到新题需要和刷过的题总结归类到一起,才能以不变应万变,真正提高。
因此,照着这个分类来一波吧,保证有奇效,我自己受益良多!
这个课程来自于educative,是一个美国的算法面试方面很出色的网课平台。
Grokking the Coding Interview: Patterns for Coding Questionswww.educative.iowww.educative.io
这门课程是一个算法总结提高的课程,它把算法面试中可能遇到的题分成了各种模式,每类题各个击破。
(如果你需要上面这些算法课程,那么你可以使用 awesome-developer 的折扣码获得网站所有课程的额外15%off!上面的折扣码针对单独购买所有课程有效。
如果想买订阅(Subscriptions)的小伙伴,则可以用 0820-ZH93025 (必须一模一样输入)的coupon code来获取额外八折的优惠 按年和按月均适用,折扣码十月四号过期,有需要的小伙伴抓紧)。
比如有最经典的sliding window模式,Two pointers模式,快慢指针模式,合并intervals模式,cyclic sort模式,in-place翻转链表模式,树上的BFS,树上的DFS,双Heaps模式,subsets模式,二分法变种,Top K模式,多路模式(K-ways),0/1背包,拓扑排序。
需要的小伙伴就去来一波吧!
他家最最出名的还是这门Grokking the System Design Interview, 但凡提到准备系统设计,这门课都上入门必推的:
Grokking the System Design Interviewwww.educative.iowww.educative.io
以及OOD: Grokking the Object Oriented Design Interview
Grokking the Object Oriented Design Interview - Learn Interactivelywww.educative.iowww.educative.io
方便大家阅读,我把内容也贴出来放在这个回答下:
1. Pattern: Sliding window,滑动窗口类型
滑动窗口类型的题目经常是用来执行数组或是链表上某个区间(窗口)上的操作。比如找最长的全为1的子数组长度。滑动窗口一般从第一个元素开始,一直往右边一个一个元素挪动。当然了,根据题目要求,我们可能有固定窗口大小的情况,也有窗口的大小变化的情况。
下面是一些我们用来判断我们可能需要上滑动窗口策略的方法:
- 这个问题的输入是一些线性结构:比如链表呀,数组啊,字符串啊之类的
- 让你去求最长/最短子字符串或是某些特定的长度要求
经典题目:
Maximum Sum Subarray of Size K (easy)
Smallest Subarray with a given sum (easy)
Longest Substring with K Distinct Characters (medium)
Fruits into Baskets (medium)
No-repeat Substring (hard)
Longest Substring with Same Letters after Replacement (hard)
Longest Subarray with Ones after Replacement (hard)
2. Pattern: two points, 双指针类型
双指针是这样的模式:两个指针朝着左右方向移动(双指针分为同向双指针和异向双指针),直到他们有一个或是两个都满足某种条件。双指针通常用在排好序的数组或是链表中寻找对子。比如,你需要去比较数组中每个元素和其他元素的关系时,你就需要用到双指针了。
我们需要双指针的原因是:如果你只用一个指针的话,你得来回跑才能在数组中找到你需要的答案。这一个指针来来回回的过程就很耗时和浪费空间了 — 这是考虑算法的复杂度分析的时候的重要概念。虽然brute force一个指针的解法可能会奏效,但时间复杂度一般会是O(n²)。在很多情况下,双指针能帮助我们找到空间或是时间复杂度更低的解。
识别使用双指针的招数:
- 一般来说,数组或是链表是排好序的,你得在里头找一些组合满足某种限制条件