《异类——不一样的成功启示录》
A*算法
加密算法
- B-Tree B树
- red-black tree 红黑树
- avl tree 平衡二叉树
- splay tree 伸展树
- 前序(Pre-order):根-左-右
- 中序(In-order):左-根-右
- 后序(Post-order):左-右-根
数组、链表leetcode实战
- https://leetcode.com/problems/reverse-linked-list/
- https://leetcode.com/problems/linked-list-cycle
- https://leetcode.com/problems/swap-nodes-in-pairs
- https://leetcode.com/problems/linked-list-cycle-ii
- https://leetcode.com/problems/reverse-nodes-in-k-group/
堆栈、队列
- https://leetcode.com/problems/implement-queue-using-stacks/solution/
- https://leetcode.com/problems/implement-stack-using-queues/description/
- https://leetcode.com/problems/valid-parentheses/description/
优先队列
- https://leetcode.com/problems/kth-largest-element-in-a-stream/discuss/149050/Java-Priority-Queue
- https://leetcode.com/problems/sliding-window-maximum/
哈希表
- https://leetcode.com/problems/valid-anagram/description/
- https://leetcode.com/problems/two-sum/description/
- https://leetcode.com/problems/3sum/description/
- https://leetcode.com/problems/4sum/
- https://leetcode.com/problems/group-anagrams/description/
树
- https://leetcode.com/problems/validate-binary-search-tree
- https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/
- https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/
分治、递归、回溯
- https://leetcode.com/problems/powx-n/description/
- https://leetcode.com/problems/majority-element/description/
- https://leetcode.com/problems/maximum-subarray/description/
- https://leetcode.com/problems/valid-anagram/#/description
- https://leetcode.com/problems/find-all-anagrams-in-a-string/#/description
- https://leetcode.com/problems/anagrams/#/description
贪心算法
贪⼼法(⼜称贪⼼算法、贪婪算法):在对问题求解时,总是做出在当前看来是最好的选择
什么场景能够使用贪心算法?
问题能够分解成⼦问题来解决,⼦问题的最优解能递推到最终问题的最优解。这种⼦问题最优解成为最优⼦结构
- https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/description/
- https://leetcode.com/problems/lemonade-change/description/
- https://leetcode.com/problems/assign-cookies/description/
- https://leetcode.com/problems/walking-robot-simulation/description/
深度优先、广度优先
- https://leetcode.com/problems/binary-tree-level-order-traversal/
- https://leetcode.com/problems/maximum-depth-of-binary-tree/
- https://leetcode.com/problems/minimum-depth-of-binary-tree/description/
- https://leetcode.com/problems/generate-parentheses/
剪枝
- https://leetcode.com/problems/n-queens/
- https://leetcode.com/problems/n-queens-ii/
- https://leetcode.com/problems/valid-sudoku/description/
- https://leetcode.com/problems/sudoku-solver/#/description
二分查找
- Sorted(单调递增或者递减)
- Bounded(存在上下界)
Accessible by index(能够通过索引访问)
- https://leetcode.com/problems/valid-perfect-square/
字典树
Trie树,即字典树,⼜称单词查找树或键树,是一种树形结构,是一种哈希树的变种。典型应用是用于统计和排序大量的字符串(但不仅限于字符串),所以经常被搜索引擎用于文本词频统计
它的优点是:最大限度地减少无谓的字符串⽐较,查询效率⽐哈希表⾼
Trie的核⼼思想是空间换时间。利用字符串的公共前缀来降低查询时间的开销以达到提高效率的目的
- 根节点不包含字符,除根节点外每一个节点都只包含一个字符
- 从根节点到某一节点,路径上经过的字符连接起来,为该节点对应的字符串
每个节点的所有子节点包含的字符都不相同
https://leetcode.com/problems/implement-trie-prefix-tree/#/description
- https://leetcode.com/problems/word-search-ii/
位运算
- https://leetcode.com/problems/number-of-1-bits/
- https://leetcode.com/problems/power-of-two/
- https://leetcode.com/problems/counting-bits/description/
- https://leetcode.com/problems/n-queens-ii/description/
动态规划
- 递归 + 记忆化 —> 递推
- 状态的定义:opt[n], dp[n] ...
- 状态转移⽅方程:opt[n] = best_of(opt[n-1], opt[n-2], ...)
- 最优⼦结构
斐波那契数列的递推公式:F[n] = F[n-1] + F[n-2]
$f[0] = 0;
$f[1] = 1;
$n = 10;
for ($i = 2; $i < $n; $i++) {
$f[$i] = $f[$i - 1] + $f[$i - 2];
}
print_r($f);
动态规划 vs 回溯 vs 贪⼼算法
回溯(递归):重复计算 ,这样计算斐波那契数列的话会开n层空间 贪心算法:永远局部最优 动态规划:记录局部最优子结构/多种记录值
- https://leetcode.com/problems/climbing-stairs/description/
- https://leetcode.com/problems/triangle/description/
- https://leetcode.com/problems/maximum-product-subarray/description/
- https://leetcode.com/problems/best-time-to-buy-and-sell-stock/#/description
- https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/
- https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/
- https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/
- https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/
- https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/
- https://leetcode.com/problems/longest-increasing-subsequence
- https://leetcode.com/problems/coin-change/
- https://leetcode.com/problems/edit-distance/