├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ ├── others.md │ └── translate.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── README.md ├── contributor.jpg ├── pictures ├── 4keyboard │ ├── 1.jpg │ └── title.png ├── BST │ ├── BST_example.png │ ├── bst_deletion_case_1.png │ ├── bst_deletion_case_2.png │ ├── bst_deletion_case_3.png │ └── 假BST.png ├── Chrome插件 │ ├── baidumonkey.png │ ├── baidu广告.png │ ├── csdnBlock.png │ ├── githubzip.png │ ├── listen1.png │ ├── monkey.png │ ├── oneTab.png │ ├── pin.png │ ├── tree.png │ └── youhou优化.png ├── LCS │ ├── 1.png │ ├── 2.png │ ├── 3.png │ ├── dp.png │ └── lcs.png ├── LRU算法 │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ └── put.jpg ├── algo4 │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ └── title.png ├── backtrack │ ├── ink-image (1).png │ ├── ink-image (2).png │ ├── ink-image (3).png │ ├── ink-image (4).png │ ├── ink-image (5).png │ ├── ink-image (6).png │ ├── ink-image.png │ ├── nqueens.png │ ├── permutation.png │ ├── 代码.png │ ├── 代码1.png │ ├── 代码2.png │ ├── 代码3.png │ └── 全排列.png ├── backtracking │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ ├── 5.jpg │ ├── 6.jpg │ └── 7.jpg ├── calculator │ ├── 1.1.jpg │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ ├── 5.jpg │ └── 6.jpg ├── cover.jpg ├── dupmissing │ ├── 1.gif │ ├── 2.jpg │ └── 3.jpg ├── editDistance │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ ├── 5.jpg │ ├── 6.jpg │ ├── delete.gif │ ├── dp.jpg │ ├── edit.gif │ ├── insert.gif │ ├── replace.gif │ └── title.png ├── floodfill │ ├── floodfill.gif │ ├── floodfill.png │ ├── leetcode.png │ ├── ppt1.PNG │ ├── ppt2.PNG │ ├── ppt3.PNG │ ├── ppt4.PNG │ ├── ppt5.PNG │ ├── xiaoxiaole.jpg │ ├── 扫雷.png │ ├── 抠图.jpeg │ └── 抠图.jpg ├── group.jpg ├── header.jpg ├── heap │ ├── 1.png │ ├── delete.gif │ ├── insert.gif │ ├── sink.gif │ └── swim.gif ├── intersection │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.gif │ └── title.png ├── interval │ ├── 1.gif │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ ├── title1.png │ └── title2.png ├── kgroup │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ ├── 5.jpg │ ├── 6.jpg │ ├── 7.jpg │ ├── 8.gif │ └── title.png ├── kmp │ ├── 1.gif │ ├── 2.gif │ ├── 3.gif │ ├── A.gif │ ├── allstate.jpg │ ├── back.jpg │ ├── dfa.gif │ ├── exp1.jpg │ ├── exp2.jpg │ ├── exp3.jpg │ ├── exp4.jpg │ ├── exp5.jpg │ ├── exp6.jpg │ ├── exp7.jpg │ ├── forward.jpg │ ├── kmp.gif │ ├── shadow.jpg │ ├── shadow1.jpg │ ├── shadow2.jpg │ ├── state.jpg │ ├── state2.jpg │ ├── state4.jpg │ ├── txt1.jpg │ ├── txt2.jpg │ ├── txt3.jpg │ ├── txt4.jpg │ └── z.jpg ├── labuladong.png ├── linux-fs │ ├── application.png │ ├── apt.png │ ├── bin.png │ ├── boot.png │ ├── cpu.png │ ├── desktop.png │ ├── dev.png │ ├── etc.png │ ├── home.png │ ├── linux-filesystem.png │ ├── log.png │ ├── opt.png │ ├── proc.png │ ├── root.png │ ├── sbin.png │ ├── tmp.png │ ├── usr.png │ └── usrbin.png ├── linuxProcess │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ ├── 5.jpg │ ├── 6.jpg │ ├── 7.jpg │ └── 8.jpg ├── linuxshell │ └── 1.png ├── mergeInterval │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.gif │ └── title.png ├── online │ ├── 1.png │ ├── 10.png │ ├── 11.png │ ├── 2.png │ ├── 3.png │ ├── 4.png │ ├── 5.png │ ├── 6.png │ ├── 7.png │ ├── 8.png │ └── 9.png ├── others │ └── leetcode.jpeg ├── pancakeSort │ ├── 1.jpg │ ├── 2.png │ ├── 3.jpg │ ├── 4.jpg │ └── title.png ├── pay.jpg ├── plugin │ ├── chrome.gif │ ├── chrome.jpg │ ├── jetbrain.gif │ ├── jetbrain.jpg │ ├── vscode.gif │ ├── vscode.jpg │ └── 全家桶.jpg ├── prime │ └── 1.gif ├── qrcode.jpg ├── redis入侵 │ ├── 1.png │ ├── 2.png │ ├── 3.png │ ├── 4.png │ ├── 5.png │ └── 6.png ├── robber │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── title.png │ └── title1.png ├── session │ ├── 1.png │ ├── 2.png │ ├── 3.png │ └── 4.jpg ├── souyisou.png ├── souyisou2.png ├── unionfind │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ ├── 5.jpg │ ├── 6.jpg │ ├── 7.jpg │ ├── 8.jpg │ └── 9.gif ├── unionfind应用 │ ├── 1.jpg │ ├── 2.jpg │ └── 3.jpg ├── youtube │ ├── 1.png │ ├── 1573133096614.jpeg │ ├── 1573133131308.jpeg │ ├── 2.jpg │ ├── 3.jpg │ └── 4.jpg ├── 二分应用 │ ├── title1.png │ └── title2.png ├── 二分查找 │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ ├── binarySearch1.png │ ├── binarySearch2.png │ └── poem.png ├── 位操作 │ ├── 1.png │ └── title.png ├── 信封嵌套 │ ├── 0.jpg │ ├── 1.jpg │ ├── 2.jpg │ └── title.png ├── 全家桶.jpg ├── 前缀和 │ ├── 1.jpg │ ├── 2.jpg │ └── title.png ├── 动态规划详解 │ ├── coindp.png │ ├── coinfunc.png │ ├── cointree.png │ ├── fibdp.png │ ├── fibfunc.png │ ├── fibmemo.png │ ├── fibtree.png │ ├── img_20190514_013033.441.png │ ├── img_20190514_013830.397.png │ ├── ink-image (1).png │ ├── ink-image (2).png │ ├── ink-image (3).png │ ├── ink-image (4).png │ └── ink-image.png ├── 动态规划详解进阶 │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ ├── 5.jpg │ ├── 6.jpg │ ├── coin.png │ └── fib.png ├── 单调栈 │ ├── 1.png │ ├── 2.png │ └── 3.png ├── 单调队列 │ ├── 1.png │ ├── 2.png │ ├── 3.png │ └── title.png ├── 博弈问题 │ ├── 1.png │ ├── 2.png │ ├── 3.png │ └── 4.png ├── 双指针 │ ├── 1.png │ ├── 2.png │ ├── 3.png │ ├── center.png │ └── title.png ├── 反转链表 │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ ├── 5.jpg │ ├── 6.jpg │ ├── 7.jpg │ └── title.png ├── 回文 │ └── title.png ├── 回文链表 │ ├── 1.gif │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ └── 4.jpg ├── 子序列 │ ├── 1.gif │ ├── 1.jpg │ ├── 2.gif │ ├── 2.jpg │ └── 3.jpg ├── 子集 │ ├── 1.jpg │ ├── 2.jpg │ └── 3.jpg ├── 字符串乘法 │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.gif │ ├── 6.jpg │ └── title.png ├── 密码技术 │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ ├── 5.jpg │ ├── 6.jpg │ └── 7.jpg ├── 座位调度 │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ ├── 5.jpg │ ├── 6.jpg │ └── 7.jpg ├── 扔鸡蛋 │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ └── dp.png ├── 接雨水 │ ├── 0.jpg │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ ├── 5.jpg │ └── title.png ├── 数组交换 │ ├── ink-image (1).png │ ├── ink-image (2).png │ ├── ink-image (3).png │ └── ink-image.png ├── 最优子结构 │ └── 1.jpg ├── 最长回文子序列 │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ └── 5.jpg ├── 最长递增子序列 │ ├── 1.jpeg │ ├── 2.jpeg │ ├── 3.jpeg │ ├── gif1.gif │ ├── gif2.gif │ ├── poker1.jpeg │ ├── poker2.jpeg │ ├── poker3.jpeg │ ├── poker4.jpeg │ └── title.png ├── 有序数组去重 │ ├── 1.gif │ ├── 2.gif │ └── title.png ├── 栈队列 │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ ├── 5.jpg │ └── 6.jpg ├── 概率问题 │ ├── p.png │ ├── p.svg │ ├── sanmen.png │ ├── sanmen.svg │ └── tree.png ├── 正则 │ ├── 1.jpeg │ ├── 2.jpeg │ ├── 3.jpeg │ ├── 4.jpeg │ ├── example.png │ └── title.png ├── 洗牌算法 │ ├── 1.png │ ├── 2.png │ ├── 3.png │ ├── 4.png │ ├── 5.jpg │ └── 6.png ├── 滑动窗口 │ ├── 0.png │ ├── 1.png │ ├── 2.png │ ├── 3.png │ ├── title1.png │ ├── title2.png │ └── title3.png ├── 缺失元素 │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── title.png │ └── xor.png ├── 股票问题 │ ├── 1.png │ └── title.png └── 设计Twitter │ ├── design.png │ ├── merge.gif │ ├── tweet.jpg │ └── user.jpg ├── starHistory.jpg ├── starHistory.png ├── 动态规划系列 ├── LCS.md ├── README.md ├── 动态规划之KMP字符匹配算法.md ├── 动态规划之博弈问题.md ├── 动态规划之四键键盘.md ├── 动态规划之正则表达.md ├── 动态规划设计:最长递增子序列.md ├── 动态规划详解进阶.md ├── 单词拼接.md ├── 团灭股票问题.md ├── 子序列问题模板.md ├── 抢房子.md ├── 最优子结构.md ├── 状态压缩技巧.md ├── 编辑距离.md ├── 背包问题.md ├── 贪心算法之区间调度问题.md ├── 高楼扔鸡蛋问题.md └── 魔塔.md ├── 多语言解法代码 ├── contribution-guide.md └── solution_code.md ├── 技术 ├── linuxshell.md ├── linux进程.md ├── redis入侵.md ├── session和cookie.md ├── 刷题技巧.md ├── 在线练习平台.md └── 密码技术.md ├── 数据结构系列 ├── BST1.md ├── BST2.md ├── README.md ├── dijkstra算法.md ├── 二叉堆详解实现优先级队列.md ├── 二叉树总结.md ├── 二叉树系列1.md ├── 二叉树系列2.md ├── 单调栈.md ├── 单调队列.md ├── 图.md ├── 实现计算器.md ├── 拓扑排序.md ├── 设计Twitter.md ├── 递归反转链表的一部分.md └── 队列实现栈栈实现队列.md ├── 算法思维系列 ├── BFS框架.md ├── BFS解决滑动拼图.md ├── README.md ├── UnionFind算法详解.md ├── 二分查找详解.md ├── 几个反直觉的概率问题.md ├── 前缀和技巧.md ├── 双指针技巧.md ├── 回溯算法详解修订版.md ├── 字符串乘法.md ├── 学习数据结构和算法的高效方法.md ├── 差分技巧.md ├── 常用的位操作.md ├── 洗牌算法.md ├── 滑动窗口技巧进阶.md ├── 烧饼排序.md ├── 花式遍历.md └── 集合划分.md └── 高频面试系列 ├── LRU算法.md ├── README.md ├── k个一组反转链表.md ├── 一行代码解决的智力题.md ├── 二分查找判定子序列.md ├── 二分运用.md ├── 判断回文链表.md ├── 名人问题.md ├── 子集排列组合.md ├── 安排会议室.md ├── 岛屿题目.md ├── 座位调度.md ├── 打印素数.md ├── 接雨水.md ├── 缺失和重复的元素.md └── 随机权重.md /.gitattributes: -------------------------------------------------------------------------------- 1 | *.md linguist-detectable=true 2 | *.md linguist-documentation=false -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: 报告错误的解法代码 2 | title: "[bug][这里替换为出错的编程语言] 这里替换为出错的力扣题目标识符" 3 | description: "反馈我的刷题全家桶中的错误。" 4 | labels: [ "help wanted" ] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | 力扣题目标识符就是题目 URL 的最后一部分。比如 [https://leetcode.cn/problems/search-a-2d-matrix/](https://leetcode.cn/problems/search-a-2d-matrix/) 这道题标识符就是 `search-a-2d-matrix`。请补全 issue 题目,示例:`[bug][golang] search-a-2d-matrix`. 10 | 11 | - type: checkboxes 12 | attributes: 13 | label: 请在提交 bug 之前先搜索 14 | description: > 15 | 请先在 [issues](https://github.com/labuladong/fucking-algorithm/issues) 列表中搜索对应题目的标识符,确保你提的这个 bug 还没有被提交过。 16 | options: 17 | - label: > 18 | 我已经搜索过 [issues](https://github.com/labuladong/fucking-algorithm/issues),没有发现相同的 bug。 19 | required: true 20 | - type: input 21 | attributes: 22 | label: 出错的题目链接 23 | description: | 24 | 输入力扣的题目链接 25 | placeholder: 例如 https://leetcode.cn/problems/search-a-2d-matrix/ 26 | validations: 27 | required: true 28 | - type: textarea 29 | attributes: 30 | label: 报错信息 31 | description: | 32 | 把出错的原因复制粘贴在这里 33 | value: | 34 | 35 | 36 | validations: 37 | required: true 38 | - type: checkboxes 39 | attributes: 40 | label: 你是否愿意提交 PR 修复这个 bug? 41 | description: > 42 | PR 规范 [见这里](https://github.com/labuladong/fucking-algorithm/issues/1113),欢迎成为本仓库的 contributor! 43 | options: 44 | - label: 我愿意! 45 | - type: markdown 46 | attributes: 47 | value: "感谢你的支持,[labuladong 的刷题全家桶](https://labuladong.github.io/article/fname.html?fname=全家桶简介) 会因你变得越来越好!" 48 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/others.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 其他issue 3 | about: 我还有一些其他的建议/问题 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/translate.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 参与翻译 3 | about: 我想参与仓库中文章的翻译工作 4 | title: 'translate ' 5 | labels: translate 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 我已阅读过[翻译组工作流程](https://github.com/labuladong/fucking-algorithm/issues/9),我已阅读过[翻译要求](https://github.com/labuladong/fucking-algorithm/blob/english/README.md),我已查看 [已完成列表](https://github.com/labuladong/fucking-algorithm/pulls?q=is%3Apr+is%3Aclosed),确保我要翻译的文章还没有被翻译。 19 | 20 | 我将开始翻译如下文章(点击可查看目标文章): 21 | 22 | 23 | [动态规划系列/抢房子.md](https://github.com/labuladong/fucking-algorithm/blob/master/动态规划系列/抢房子.md) 24 | 25 | 我对如何翻译此文章已经心中有数,我准备将它翻译成:**英文** 26 | 27 | 28 | **预计 3 天内翻译完成**,我会尽可能快地完成翻译,主仓库会对第一个完成的 pull request 添加翻译者昵称/姓名及个人链接。 -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | Fixes 10 | 11 | 我修改的是如下题目的 xx 解法: 12 | 13 | 14 | 15 | 通过截图如下: 16 | 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_store 2 | -------------------------------------------------------------------------------- /contributor.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/contributor.jpg -------------------------------------------------------------------------------- /pictures/4keyboard/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/4keyboard/1.jpg -------------------------------------------------------------------------------- /pictures/4keyboard/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/4keyboard/title.png -------------------------------------------------------------------------------- /pictures/BST/BST_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/BST/BST_example.png -------------------------------------------------------------------------------- /pictures/BST/bst_deletion_case_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/BST/bst_deletion_case_1.png -------------------------------------------------------------------------------- /pictures/BST/bst_deletion_case_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/BST/bst_deletion_case_2.png -------------------------------------------------------------------------------- /pictures/BST/bst_deletion_case_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/BST/bst_deletion_case_3.png -------------------------------------------------------------------------------- /pictures/BST/假BST.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/BST/假BST.png -------------------------------------------------------------------------------- /pictures/Chrome插件/baidumonkey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/Chrome插件/baidumonkey.png -------------------------------------------------------------------------------- /pictures/Chrome插件/baidu广告.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/Chrome插件/baidu广告.png -------------------------------------------------------------------------------- /pictures/Chrome插件/csdnBlock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/Chrome插件/csdnBlock.png -------------------------------------------------------------------------------- /pictures/Chrome插件/githubzip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/Chrome插件/githubzip.png -------------------------------------------------------------------------------- /pictures/Chrome插件/listen1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/Chrome插件/listen1.png -------------------------------------------------------------------------------- /pictures/Chrome插件/monkey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/Chrome插件/monkey.png -------------------------------------------------------------------------------- /pictures/Chrome插件/oneTab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/Chrome插件/oneTab.png -------------------------------------------------------------------------------- /pictures/Chrome插件/pin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/Chrome插件/pin.png -------------------------------------------------------------------------------- /pictures/Chrome插件/tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/Chrome插件/tree.png -------------------------------------------------------------------------------- /pictures/Chrome插件/youhou优化.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/Chrome插件/youhou优化.png -------------------------------------------------------------------------------- /pictures/LCS/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/LCS/1.png -------------------------------------------------------------------------------- /pictures/LCS/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/LCS/2.png -------------------------------------------------------------------------------- /pictures/LCS/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/LCS/3.png -------------------------------------------------------------------------------- /pictures/LCS/dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/LCS/dp.png -------------------------------------------------------------------------------- /pictures/LCS/lcs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/LCS/lcs.png -------------------------------------------------------------------------------- /pictures/LRU算法/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/LRU算法/1.jpg -------------------------------------------------------------------------------- /pictures/LRU算法/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/LRU算法/2.jpg -------------------------------------------------------------------------------- /pictures/LRU算法/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/LRU算法/3.jpg -------------------------------------------------------------------------------- /pictures/LRU算法/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/LRU算法/4.jpg -------------------------------------------------------------------------------- /pictures/LRU算法/put.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/LRU算法/put.jpg -------------------------------------------------------------------------------- /pictures/algo4/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/algo4/1.jpg -------------------------------------------------------------------------------- /pictures/algo4/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/algo4/2.jpg -------------------------------------------------------------------------------- /pictures/algo4/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/algo4/3.jpg -------------------------------------------------------------------------------- /pictures/algo4/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/algo4/title.png -------------------------------------------------------------------------------- /pictures/backtrack/ink-image (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtrack/ink-image (1).png -------------------------------------------------------------------------------- /pictures/backtrack/ink-image (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtrack/ink-image (2).png -------------------------------------------------------------------------------- /pictures/backtrack/ink-image (3).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtrack/ink-image (3).png -------------------------------------------------------------------------------- /pictures/backtrack/ink-image (4).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtrack/ink-image (4).png -------------------------------------------------------------------------------- /pictures/backtrack/ink-image (5).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtrack/ink-image (5).png -------------------------------------------------------------------------------- /pictures/backtrack/ink-image (6).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtrack/ink-image (6).png -------------------------------------------------------------------------------- /pictures/backtrack/ink-image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtrack/ink-image.png -------------------------------------------------------------------------------- /pictures/backtrack/nqueens.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtrack/nqueens.png -------------------------------------------------------------------------------- /pictures/backtrack/permutation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtrack/permutation.png -------------------------------------------------------------------------------- /pictures/backtrack/代码.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtrack/代码.png -------------------------------------------------------------------------------- /pictures/backtrack/代码1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtrack/代码1.png -------------------------------------------------------------------------------- /pictures/backtrack/代码2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtrack/代码2.png -------------------------------------------------------------------------------- /pictures/backtrack/代码3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtrack/代码3.png -------------------------------------------------------------------------------- /pictures/backtrack/全排列.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtrack/全排列.png -------------------------------------------------------------------------------- /pictures/backtracking/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtracking/1.jpg -------------------------------------------------------------------------------- /pictures/backtracking/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtracking/2.jpg -------------------------------------------------------------------------------- /pictures/backtracking/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtracking/3.jpg -------------------------------------------------------------------------------- /pictures/backtracking/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtracking/4.jpg -------------------------------------------------------------------------------- /pictures/backtracking/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtracking/5.jpg -------------------------------------------------------------------------------- /pictures/backtracking/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtracking/6.jpg -------------------------------------------------------------------------------- /pictures/backtracking/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/backtracking/7.jpg -------------------------------------------------------------------------------- /pictures/calculator/1.1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/calculator/1.1.jpg -------------------------------------------------------------------------------- /pictures/calculator/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/calculator/1.jpg -------------------------------------------------------------------------------- /pictures/calculator/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/calculator/2.jpg -------------------------------------------------------------------------------- /pictures/calculator/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/calculator/3.jpg -------------------------------------------------------------------------------- /pictures/calculator/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/calculator/4.jpg -------------------------------------------------------------------------------- /pictures/calculator/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/calculator/5.jpg -------------------------------------------------------------------------------- /pictures/calculator/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/calculator/6.jpg -------------------------------------------------------------------------------- /pictures/cover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/cover.jpg -------------------------------------------------------------------------------- /pictures/dupmissing/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/dupmissing/1.gif -------------------------------------------------------------------------------- /pictures/dupmissing/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/dupmissing/2.jpg -------------------------------------------------------------------------------- /pictures/dupmissing/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/dupmissing/3.jpg -------------------------------------------------------------------------------- /pictures/editDistance/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/editDistance/1.jpg -------------------------------------------------------------------------------- /pictures/editDistance/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/editDistance/2.jpg -------------------------------------------------------------------------------- /pictures/editDistance/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/editDistance/3.jpg -------------------------------------------------------------------------------- /pictures/editDistance/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/editDistance/4.jpg -------------------------------------------------------------------------------- /pictures/editDistance/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/editDistance/5.jpg -------------------------------------------------------------------------------- /pictures/editDistance/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/editDistance/6.jpg -------------------------------------------------------------------------------- /pictures/editDistance/delete.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/editDistance/delete.gif -------------------------------------------------------------------------------- /pictures/editDistance/dp.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/editDistance/dp.jpg -------------------------------------------------------------------------------- /pictures/editDistance/edit.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/editDistance/edit.gif -------------------------------------------------------------------------------- /pictures/editDistance/insert.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/editDistance/insert.gif -------------------------------------------------------------------------------- /pictures/editDistance/replace.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/editDistance/replace.gif -------------------------------------------------------------------------------- /pictures/editDistance/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/editDistance/title.png -------------------------------------------------------------------------------- /pictures/floodfill/floodfill.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/floodfill/floodfill.gif -------------------------------------------------------------------------------- /pictures/floodfill/floodfill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/floodfill/floodfill.png -------------------------------------------------------------------------------- /pictures/floodfill/leetcode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/floodfill/leetcode.png -------------------------------------------------------------------------------- /pictures/floodfill/ppt1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/floodfill/ppt1.PNG -------------------------------------------------------------------------------- /pictures/floodfill/ppt2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/floodfill/ppt2.PNG -------------------------------------------------------------------------------- /pictures/floodfill/ppt3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/floodfill/ppt3.PNG -------------------------------------------------------------------------------- /pictures/floodfill/ppt4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/floodfill/ppt4.PNG -------------------------------------------------------------------------------- /pictures/floodfill/ppt5.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/floodfill/ppt5.PNG -------------------------------------------------------------------------------- /pictures/floodfill/xiaoxiaole.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/floodfill/xiaoxiaole.jpg -------------------------------------------------------------------------------- /pictures/floodfill/扫雷.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/floodfill/扫雷.png -------------------------------------------------------------------------------- /pictures/floodfill/抠图.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/floodfill/抠图.jpeg -------------------------------------------------------------------------------- /pictures/floodfill/抠图.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/floodfill/抠图.jpg -------------------------------------------------------------------------------- /pictures/group.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/group.jpg -------------------------------------------------------------------------------- /pictures/header.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/header.jpg -------------------------------------------------------------------------------- /pictures/heap/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/heap/1.png -------------------------------------------------------------------------------- /pictures/heap/delete.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/heap/delete.gif -------------------------------------------------------------------------------- /pictures/heap/insert.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/heap/insert.gif -------------------------------------------------------------------------------- /pictures/heap/sink.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/heap/sink.gif -------------------------------------------------------------------------------- /pictures/heap/swim.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/heap/swim.gif -------------------------------------------------------------------------------- /pictures/intersection/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/intersection/1.jpg -------------------------------------------------------------------------------- /pictures/intersection/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/intersection/2.jpg -------------------------------------------------------------------------------- /pictures/intersection/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/intersection/3.jpg -------------------------------------------------------------------------------- /pictures/intersection/4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/intersection/4.gif -------------------------------------------------------------------------------- /pictures/intersection/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/intersection/title.png -------------------------------------------------------------------------------- /pictures/interval/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/interval/1.gif -------------------------------------------------------------------------------- /pictures/interval/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/interval/2.jpg -------------------------------------------------------------------------------- /pictures/interval/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/interval/3.jpg -------------------------------------------------------------------------------- /pictures/interval/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/interval/4.jpg -------------------------------------------------------------------------------- /pictures/interval/title1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/interval/title1.png -------------------------------------------------------------------------------- /pictures/interval/title2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/interval/title2.png -------------------------------------------------------------------------------- /pictures/kgroup/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kgroup/1.jpg -------------------------------------------------------------------------------- /pictures/kgroup/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kgroup/2.jpg -------------------------------------------------------------------------------- /pictures/kgroup/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kgroup/3.jpg -------------------------------------------------------------------------------- /pictures/kgroup/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kgroup/4.jpg -------------------------------------------------------------------------------- /pictures/kgroup/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kgroup/5.jpg -------------------------------------------------------------------------------- /pictures/kgroup/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kgroup/6.jpg -------------------------------------------------------------------------------- /pictures/kgroup/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kgroup/7.jpg -------------------------------------------------------------------------------- /pictures/kgroup/8.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kgroup/8.gif -------------------------------------------------------------------------------- /pictures/kgroup/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kgroup/title.png -------------------------------------------------------------------------------- /pictures/kmp/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/1.gif -------------------------------------------------------------------------------- /pictures/kmp/2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/2.gif -------------------------------------------------------------------------------- /pictures/kmp/3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/3.gif -------------------------------------------------------------------------------- /pictures/kmp/A.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/A.gif -------------------------------------------------------------------------------- /pictures/kmp/allstate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/allstate.jpg -------------------------------------------------------------------------------- /pictures/kmp/back.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/back.jpg -------------------------------------------------------------------------------- /pictures/kmp/dfa.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/dfa.gif -------------------------------------------------------------------------------- /pictures/kmp/exp1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/exp1.jpg -------------------------------------------------------------------------------- /pictures/kmp/exp2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/exp2.jpg -------------------------------------------------------------------------------- /pictures/kmp/exp3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/exp3.jpg -------------------------------------------------------------------------------- /pictures/kmp/exp4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/exp4.jpg -------------------------------------------------------------------------------- /pictures/kmp/exp5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/exp5.jpg -------------------------------------------------------------------------------- /pictures/kmp/exp6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/exp6.jpg -------------------------------------------------------------------------------- /pictures/kmp/exp7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/exp7.jpg -------------------------------------------------------------------------------- /pictures/kmp/forward.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/forward.jpg -------------------------------------------------------------------------------- /pictures/kmp/kmp.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/kmp.gif -------------------------------------------------------------------------------- /pictures/kmp/shadow.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/shadow.jpg -------------------------------------------------------------------------------- /pictures/kmp/shadow1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/shadow1.jpg -------------------------------------------------------------------------------- /pictures/kmp/shadow2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/shadow2.jpg -------------------------------------------------------------------------------- /pictures/kmp/state.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/state.jpg -------------------------------------------------------------------------------- /pictures/kmp/state2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/state2.jpg -------------------------------------------------------------------------------- /pictures/kmp/state4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/state4.jpg -------------------------------------------------------------------------------- /pictures/kmp/txt1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/txt1.jpg -------------------------------------------------------------------------------- /pictures/kmp/txt2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/txt2.jpg -------------------------------------------------------------------------------- /pictures/kmp/txt3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/txt3.jpg -------------------------------------------------------------------------------- /pictures/kmp/txt4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/txt4.jpg -------------------------------------------------------------------------------- /pictures/kmp/z.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/kmp/z.jpg -------------------------------------------------------------------------------- /pictures/labuladong.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/labuladong.png -------------------------------------------------------------------------------- /pictures/linux-fs/application.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linux-fs/application.png -------------------------------------------------------------------------------- /pictures/linux-fs/apt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linux-fs/apt.png -------------------------------------------------------------------------------- /pictures/linux-fs/bin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linux-fs/bin.png -------------------------------------------------------------------------------- /pictures/linux-fs/boot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linux-fs/boot.png -------------------------------------------------------------------------------- /pictures/linux-fs/cpu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linux-fs/cpu.png -------------------------------------------------------------------------------- /pictures/linux-fs/desktop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linux-fs/desktop.png -------------------------------------------------------------------------------- /pictures/linux-fs/dev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linux-fs/dev.png -------------------------------------------------------------------------------- /pictures/linux-fs/etc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linux-fs/etc.png -------------------------------------------------------------------------------- /pictures/linux-fs/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linux-fs/home.png -------------------------------------------------------------------------------- /pictures/linux-fs/linux-filesystem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linux-fs/linux-filesystem.png -------------------------------------------------------------------------------- /pictures/linux-fs/log.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linux-fs/log.png -------------------------------------------------------------------------------- /pictures/linux-fs/opt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linux-fs/opt.png -------------------------------------------------------------------------------- /pictures/linux-fs/proc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linux-fs/proc.png -------------------------------------------------------------------------------- /pictures/linux-fs/root.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linux-fs/root.png -------------------------------------------------------------------------------- /pictures/linux-fs/sbin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linux-fs/sbin.png -------------------------------------------------------------------------------- /pictures/linux-fs/tmp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linux-fs/tmp.png -------------------------------------------------------------------------------- /pictures/linux-fs/usr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linux-fs/usr.png -------------------------------------------------------------------------------- /pictures/linux-fs/usrbin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linux-fs/usrbin.png -------------------------------------------------------------------------------- /pictures/linuxProcess/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linuxProcess/1.jpg -------------------------------------------------------------------------------- /pictures/linuxProcess/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linuxProcess/2.jpg -------------------------------------------------------------------------------- /pictures/linuxProcess/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linuxProcess/3.jpg -------------------------------------------------------------------------------- /pictures/linuxProcess/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linuxProcess/4.jpg -------------------------------------------------------------------------------- /pictures/linuxProcess/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linuxProcess/5.jpg -------------------------------------------------------------------------------- /pictures/linuxProcess/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linuxProcess/6.jpg -------------------------------------------------------------------------------- /pictures/linuxProcess/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linuxProcess/7.jpg -------------------------------------------------------------------------------- /pictures/linuxProcess/8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linuxProcess/8.jpg -------------------------------------------------------------------------------- /pictures/linuxshell/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/linuxshell/1.png -------------------------------------------------------------------------------- /pictures/mergeInterval/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/mergeInterval/1.jpg -------------------------------------------------------------------------------- /pictures/mergeInterval/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/mergeInterval/2.jpg -------------------------------------------------------------------------------- /pictures/mergeInterval/3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/mergeInterval/3.gif -------------------------------------------------------------------------------- /pictures/mergeInterval/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/mergeInterval/title.png -------------------------------------------------------------------------------- /pictures/online/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/online/1.png -------------------------------------------------------------------------------- /pictures/online/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/online/10.png -------------------------------------------------------------------------------- /pictures/online/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/online/11.png -------------------------------------------------------------------------------- /pictures/online/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/online/2.png -------------------------------------------------------------------------------- /pictures/online/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/online/3.png -------------------------------------------------------------------------------- /pictures/online/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/online/4.png -------------------------------------------------------------------------------- /pictures/online/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/online/5.png -------------------------------------------------------------------------------- /pictures/online/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/online/6.png -------------------------------------------------------------------------------- /pictures/online/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/online/7.png -------------------------------------------------------------------------------- /pictures/online/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/online/8.png -------------------------------------------------------------------------------- /pictures/online/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/online/9.png -------------------------------------------------------------------------------- /pictures/others/leetcode.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/others/leetcode.jpeg -------------------------------------------------------------------------------- /pictures/pancakeSort/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/pancakeSort/1.jpg -------------------------------------------------------------------------------- /pictures/pancakeSort/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/pancakeSort/2.png -------------------------------------------------------------------------------- /pictures/pancakeSort/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/pancakeSort/3.jpg -------------------------------------------------------------------------------- /pictures/pancakeSort/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/pancakeSort/4.jpg -------------------------------------------------------------------------------- /pictures/pancakeSort/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/pancakeSort/title.png -------------------------------------------------------------------------------- /pictures/pay.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/pay.jpg -------------------------------------------------------------------------------- /pictures/plugin/chrome.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/plugin/chrome.gif -------------------------------------------------------------------------------- /pictures/plugin/chrome.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/plugin/chrome.jpg -------------------------------------------------------------------------------- /pictures/plugin/jetbrain.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/plugin/jetbrain.gif -------------------------------------------------------------------------------- /pictures/plugin/jetbrain.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/plugin/jetbrain.jpg -------------------------------------------------------------------------------- /pictures/plugin/vscode.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/plugin/vscode.gif -------------------------------------------------------------------------------- /pictures/plugin/vscode.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/plugin/vscode.jpg -------------------------------------------------------------------------------- /pictures/plugin/全家桶.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/plugin/全家桶.jpg -------------------------------------------------------------------------------- /pictures/prime/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/prime/1.gif -------------------------------------------------------------------------------- /pictures/qrcode.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/qrcode.jpg -------------------------------------------------------------------------------- /pictures/redis入侵/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/redis入侵/1.png -------------------------------------------------------------------------------- /pictures/redis入侵/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/redis入侵/2.png -------------------------------------------------------------------------------- /pictures/redis入侵/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/redis入侵/3.png -------------------------------------------------------------------------------- /pictures/redis入侵/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/redis入侵/4.png -------------------------------------------------------------------------------- /pictures/redis入侵/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/redis入侵/5.png -------------------------------------------------------------------------------- /pictures/redis入侵/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/redis入侵/6.png -------------------------------------------------------------------------------- /pictures/robber/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/robber/1.jpg -------------------------------------------------------------------------------- /pictures/robber/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/robber/2.jpg -------------------------------------------------------------------------------- /pictures/robber/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/robber/3.jpg -------------------------------------------------------------------------------- /pictures/robber/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/robber/title.png -------------------------------------------------------------------------------- /pictures/robber/title1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/robber/title1.png -------------------------------------------------------------------------------- /pictures/session/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/session/1.png -------------------------------------------------------------------------------- /pictures/session/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/session/2.png -------------------------------------------------------------------------------- /pictures/session/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/session/3.png -------------------------------------------------------------------------------- /pictures/session/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/session/4.jpg -------------------------------------------------------------------------------- /pictures/souyisou.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/souyisou.png -------------------------------------------------------------------------------- /pictures/souyisou2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/souyisou2.png -------------------------------------------------------------------------------- /pictures/unionfind/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/unionfind/1.jpg -------------------------------------------------------------------------------- /pictures/unionfind/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/unionfind/2.jpg -------------------------------------------------------------------------------- /pictures/unionfind/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/unionfind/3.jpg -------------------------------------------------------------------------------- /pictures/unionfind/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/unionfind/4.jpg -------------------------------------------------------------------------------- /pictures/unionfind/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/unionfind/5.jpg -------------------------------------------------------------------------------- /pictures/unionfind/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/unionfind/6.jpg -------------------------------------------------------------------------------- /pictures/unionfind/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/unionfind/7.jpg -------------------------------------------------------------------------------- /pictures/unionfind/8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/unionfind/8.jpg -------------------------------------------------------------------------------- /pictures/unionfind/9.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/unionfind/9.gif -------------------------------------------------------------------------------- /pictures/unionfind应用/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/unionfind应用/1.jpg -------------------------------------------------------------------------------- /pictures/unionfind应用/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/unionfind应用/2.jpg -------------------------------------------------------------------------------- /pictures/unionfind应用/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/unionfind应用/3.jpg -------------------------------------------------------------------------------- /pictures/youtube/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/youtube/1.png -------------------------------------------------------------------------------- /pictures/youtube/1573133096614.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/youtube/1573133096614.jpeg -------------------------------------------------------------------------------- /pictures/youtube/1573133131308.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/youtube/1573133131308.jpeg -------------------------------------------------------------------------------- /pictures/youtube/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/youtube/2.jpg -------------------------------------------------------------------------------- /pictures/youtube/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/youtube/3.jpg -------------------------------------------------------------------------------- /pictures/youtube/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/youtube/4.jpg -------------------------------------------------------------------------------- /pictures/二分应用/title1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/二分应用/title1.png -------------------------------------------------------------------------------- /pictures/二分应用/title2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/二分应用/title2.png -------------------------------------------------------------------------------- /pictures/二分查找/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/二分查找/1.jpg -------------------------------------------------------------------------------- /pictures/二分查找/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/二分查找/2.jpg -------------------------------------------------------------------------------- /pictures/二分查找/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/二分查找/3.jpg -------------------------------------------------------------------------------- /pictures/二分查找/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/二分查找/4.jpg -------------------------------------------------------------------------------- /pictures/二分查找/binarySearch1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/二分查找/binarySearch1.png -------------------------------------------------------------------------------- /pictures/二分查找/binarySearch2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/二分查找/binarySearch2.png -------------------------------------------------------------------------------- /pictures/二分查找/poem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/二分查找/poem.png -------------------------------------------------------------------------------- /pictures/位操作/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/位操作/1.png -------------------------------------------------------------------------------- /pictures/位操作/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/位操作/title.png -------------------------------------------------------------------------------- /pictures/信封嵌套/0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/信封嵌套/0.jpg -------------------------------------------------------------------------------- /pictures/信封嵌套/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/信封嵌套/1.jpg -------------------------------------------------------------------------------- /pictures/信封嵌套/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/信封嵌套/2.jpg -------------------------------------------------------------------------------- /pictures/信封嵌套/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/信封嵌套/title.png -------------------------------------------------------------------------------- /pictures/全家桶.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/全家桶.jpg -------------------------------------------------------------------------------- /pictures/前缀和/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/前缀和/1.jpg -------------------------------------------------------------------------------- /pictures/前缀和/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/前缀和/2.jpg -------------------------------------------------------------------------------- /pictures/前缀和/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/前缀和/title.png -------------------------------------------------------------------------------- /pictures/动态规划详解/coindp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解/coindp.png -------------------------------------------------------------------------------- /pictures/动态规划详解/coinfunc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解/coinfunc.png -------------------------------------------------------------------------------- /pictures/动态规划详解/cointree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解/cointree.png -------------------------------------------------------------------------------- /pictures/动态规划详解/fibdp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解/fibdp.png -------------------------------------------------------------------------------- /pictures/动态规划详解/fibfunc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解/fibfunc.png -------------------------------------------------------------------------------- /pictures/动态规划详解/fibmemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解/fibmemo.png -------------------------------------------------------------------------------- /pictures/动态规划详解/fibtree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解/fibtree.png -------------------------------------------------------------------------------- /pictures/动态规划详解/img_20190514_013033.441.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解/img_20190514_013033.441.png -------------------------------------------------------------------------------- /pictures/动态规划详解/img_20190514_013830.397.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解/img_20190514_013830.397.png -------------------------------------------------------------------------------- /pictures/动态规划详解/ink-image (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解/ink-image (1).png -------------------------------------------------------------------------------- /pictures/动态规划详解/ink-image (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解/ink-image (2).png -------------------------------------------------------------------------------- /pictures/动态规划详解/ink-image (3).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解/ink-image (3).png -------------------------------------------------------------------------------- /pictures/动态规划详解/ink-image (4).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解/ink-image (4).png -------------------------------------------------------------------------------- /pictures/动态规划详解/ink-image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解/ink-image.png -------------------------------------------------------------------------------- /pictures/动态规划详解进阶/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解进阶/1.jpg -------------------------------------------------------------------------------- /pictures/动态规划详解进阶/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解进阶/2.jpg -------------------------------------------------------------------------------- /pictures/动态规划详解进阶/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解进阶/3.jpg -------------------------------------------------------------------------------- /pictures/动态规划详解进阶/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解进阶/4.jpg -------------------------------------------------------------------------------- /pictures/动态规划详解进阶/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解进阶/5.jpg -------------------------------------------------------------------------------- /pictures/动态规划详解进阶/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解进阶/6.jpg -------------------------------------------------------------------------------- /pictures/动态规划详解进阶/coin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解进阶/coin.png -------------------------------------------------------------------------------- /pictures/动态规划详解进阶/fib.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/动态规划详解进阶/fib.png -------------------------------------------------------------------------------- /pictures/单调栈/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/单调栈/1.png -------------------------------------------------------------------------------- /pictures/单调栈/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/单调栈/2.png -------------------------------------------------------------------------------- /pictures/单调栈/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/单调栈/3.png -------------------------------------------------------------------------------- /pictures/单调队列/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/单调队列/1.png -------------------------------------------------------------------------------- /pictures/单调队列/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/单调队列/2.png -------------------------------------------------------------------------------- /pictures/单调队列/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/单调队列/3.png -------------------------------------------------------------------------------- /pictures/单调队列/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/单调队列/title.png -------------------------------------------------------------------------------- /pictures/博弈问题/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/博弈问题/1.png -------------------------------------------------------------------------------- /pictures/博弈问题/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/博弈问题/2.png -------------------------------------------------------------------------------- /pictures/博弈问题/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/博弈问题/3.png -------------------------------------------------------------------------------- /pictures/博弈问题/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/博弈问题/4.png -------------------------------------------------------------------------------- /pictures/双指针/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/双指针/1.png -------------------------------------------------------------------------------- /pictures/双指针/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/双指针/2.png -------------------------------------------------------------------------------- /pictures/双指针/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/双指针/3.png -------------------------------------------------------------------------------- /pictures/双指针/center.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/双指针/center.png -------------------------------------------------------------------------------- /pictures/双指针/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/双指针/title.png -------------------------------------------------------------------------------- /pictures/反转链表/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/反转链表/1.jpg -------------------------------------------------------------------------------- /pictures/反转链表/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/反转链表/2.jpg -------------------------------------------------------------------------------- /pictures/反转链表/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/反转链表/3.jpg -------------------------------------------------------------------------------- /pictures/反转链表/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/反转链表/4.jpg -------------------------------------------------------------------------------- /pictures/反转链表/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/反转链表/5.jpg -------------------------------------------------------------------------------- /pictures/反转链表/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/反转链表/6.jpg -------------------------------------------------------------------------------- /pictures/反转链表/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/反转链表/7.jpg -------------------------------------------------------------------------------- /pictures/反转链表/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/反转链表/title.png -------------------------------------------------------------------------------- /pictures/回文/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/回文/title.png -------------------------------------------------------------------------------- /pictures/回文链表/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/回文链表/1.gif -------------------------------------------------------------------------------- /pictures/回文链表/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/回文链表/1.jpg -------------------------------------------------------------------------------- /pictures/回文链表/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/回文链表/2.jpg -------------------------------------------------------------------------------- /pictures/回文链表/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/回文链表/3.jpg -------------------------------------------------------------------------------- /pictures/回文链表/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/回文链表/4.jpg -------------------------------------------------------------------------------- /pictures/子序列/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/子序列/1.gif -------------------------------------------------------------------------------- /pictures/子序列/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/子序列/1.jpg -------------------------------------------------------------------------------- /pictures/子序列/2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/子序列/2.gif -------------------------------------------------------------------------------- /pictures/子序列/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/子序列/2.jpg -------------------------------------------------------------------------------- /pictures/子序列/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/子序列/3.jpg -------------------------------------------------------------------------------- /pictures/子集/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/子集/1.jpg -------------------------------------------------------------------------------- /pictures/子集/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/子集/2.jpg -------------------------------------------------------------------------------- /pictures/子集/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/子集/3.jpg -------------------------------------------------------------------------------- /pictures/字符串乘法/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/字符串乘法/1.jpg -------------------------------------------------------------------------------- /pictures/字符串乘法/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/字符串乘法/2.jpg -------------------------------------------------------------------------------- /pictures/字符串乘法/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/字符串乘法/3.jpg -------------------------------------------------------------------------------- /pictures/字符串乘法/4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/字符串乘法/4.gif -------------------------------------------------------------------------------- /pictures/字符串乘法/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/字符串乘法/6.jpg -------------------------------------------------------------------------------- /pictures/字符串乘法/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/字符串乘法/title.png -------------------------------------------------------------------------------- /pictures/密码技术/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/密码技术/1.jpg -------------------------------------------------------------------------------- /pictures/密码技术/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/密码技术/2.jpg -------------------------------------------------------------------------------- /pictures/密码技术/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/密码技术/3.jpg -------------------------------------------------------------------------------- /pictures/密码技术/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/密码技术/4.jpg -------------------------------------------------------------------------------- /pictures/密码技术/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/密码技术/5.jpg -------------------------------------------------------------------------------- /pictures/密码技术/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/密码技术/6.jpg -------------------------------------------------------------------------------- /pictures/密码技术/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/密码技术/7.jpg -------------------------------------------------------------------------------- /pictures/座位调度/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/座位调度/1.jpg -------------------------------------------------------------------------------- /pictures/座位调度/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/座位调度/2.jpg -------------------------------------------------------------------------------- /pictures/座位调度/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/座位调度/3.jpg -------------------------------------------------------------------------------- /pictures/座位调度/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/座位调度/4.jpg -------------------------------------------------------------------------------- /pictures/座位调度/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/座位调度/5.jpg -------------------------------------------------------------------------------- /pictures/座位调度/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/座位调度/6.jpg -------------------------------------------------------------------------------- /pictures/座位调度/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/座位调度/7.jpg -------------------------------------------------------------------------------- /pictures/扔鸡蛋/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/扔鸡蛋/1.jpg -------------------------------------------------------------------------------- /pictures/扔鸡蛋/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/扔鸡蛋/2.jpg -------------------------------------------------------------------------------- /pictures/扔鸡蛋/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/扔鸡蛋/3.jpg -------------------------------------------------------------------------------- /pictures/扔鸡蛋/dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/扔鸡蛋/dp.png -------------------------------------------------------------------------------- /pictures/接雨水/0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/接雨水/0.jpg -------------------------------------------------------------------------------- /pictures/接雨水/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/接雨水/1.jpg -------------------------------------------------------------------------------- /pictures/接雨水/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/接雨水/2.jpg -------------------------------------------------------------------------------- /pictures/接雨水/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/接雨水/3.jpg -------------------------------------------------------------------------------- /pictures/接雨水/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/接雨水/4.jpg -------------------------------------------------------------------------------- /pictures/接雨水/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/接雨水/5.jpg -------------------------------------------------------------------------------- /pictures/接雨水/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/接雨水/title.png -------------------------------------------------------------------------------- /pictures/数组交换/ink-image (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/数组交换/ink-image (1).png -------------------------------------------------------------------------------- /pictures/数组交换/ink-image (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/数组交换/ink-image (2).png -------------------------------------------------------------------------------- /pictures/数组交换/ink-image (3).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/数组交换/ink-image (3).png -------------------------------------------------------------------------------- /pictures/数组交换/ink-image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/数组交换/ink-image.png -------------------------------------------------------------------------------- /pictures/最优子结构/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/最优子结构/1.jpg -------------------------------------------------------------------------------- /pictures/最长回文子序列/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/最长回文子序列/1.jpg -------------------------------------------------------------------------------- /pictures/最长回文子序列/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/最长回文子序列/2.jpg -------------------------------------------------------------------------------- /pictures/最长回文子序列/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/最长回文子序列/3.jpg -------------------------------------------------------------------------------- /pictures/最长回文子序列/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/最长回文子序列/4.jpg -------------------------------------------------------------------------------- /pictures/最长回文子序列/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/最长回文子序列/5.jpg -------------------------------------------------------------------------------- /pictures/最长递增子序列/1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/最长递增子序列/1.jpeg -------------------------------------------------------------------------------- /pictures/最长递增子序列/2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/最长递增子序列/2.jpeg -------------------------------------------------------------------------------- /pictures/最长递增子序列/3.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/最长递增子序列/3.jpeg -------------------------------------------------------------------------------- /pictures/最长递增子序列/gif1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/最长递增子序列/gif1.gif -------------------------------------------------------------------------------- /pictures/最长递增子序列/gif2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/最长递增子序列/gif2.gif -------------------------------------------------------------------------------- /pictures/最长递增子序列/poker1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/最长递增子序列/poker1.jpeg -------------------------------------------------------------------------------- /pictures/最长递增子序列/poker2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/最长递增子序列/poker2.jpeg -------------------------------------------------------------------------------- /pictures/最长递增子序列/poker3.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/最长递增子序列/poker3.jpeg -------------------------------------------------------------------------------- /pictures/最长递增子序列/poker4.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/最长递增子序列/poker4.jpeg -------------------------------------------------------------------------------- /pictures/最长递增子序列/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/最长递增子序列/title.png -------------------------------------------------------------------------------- /pictures/有序数组去重/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/有序数组去重/1.gif -------------------------------------------------------------------------------- /pictures/有序数组去重/2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/有序数组去重/2.gif -------------------------------------------------------------------------------- /pictures/有序数组去重/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/有序数组去重/title.png -------------------------------------------------------------------------------- /pictures/栈队列/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/栈队列/1.jpg -------------------------------------------------------------------------------- /pictures/栈队列/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/栈队列/2.jpg -------------------------------------------------------------------------------- /pictures/栈队列/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/栈队列/3.jpg -------------------------------------------------------------------------------- /pictures/栈队列/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/栈队列/4.jpg -------------------------------------------------------------------------------- /pictures/栈队列/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/栈队列/5.jpg -------------------------------------------------------------------------------- /pictures/栈队列/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/栈队列/6.jpg -------------------------------------------------------------------------------- /pictures/概率问题/p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/概率问题/p.png -------------------------------------------------------------------------------- /pictures/概率问题/sanmen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/概率问题/sanmen.png -------------------------------------------------------------------------------- /pictures/概率问题/tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/概率问题/tree.png -------------------------------------------------------------------------------- /pictures/正则/1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/正则/1.jpeg -------------------------------------------------------------------------------- /pictures/正则/2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/正则/2.jpeg -------------------------------------------------------------------------------- /pictures/正则/3.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/正则/3.jpeg -------------------------------------------------------------------------------- /pictures/正则/4.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/正则/4.jpeg -------------------------------------------------------------------------------- /pictures/正则/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/正则/example.png -------------------------------------------------------------------------------- /pictures/正则/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/正则/title.png -------------------------------------------------------------------------------- /pictures/洗牌算法/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/洗牌算法/1.png -------------------------------------------------------------------------------- /pictures/洗牌算法/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/洗牌算法/2.png -------------------------------------------------------------------------------- /pictures/洗牌算法/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/洗牌算法/3.png -------------------------------------------------------------------------------- /pictures/洗牌算法/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/洗牌算法/4.png -------------------------------------------------------------------------------- /pictures/洗牌算法/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/洗牌算法/5.jpg -------------------------------------------------------------------------------- /pictures/洗牌算法/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/洗牌算法/6.png -------------------------------------------------------------------------------- /pictures/滑动窗口/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/滑动窗口/0.png -------------------------------------------------------------------------------- /pictures/滑动窗口/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/滑动窗口/1.png -------------------------------------------------------------------------------- /pictures/滑动窗口/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/滑动窗口/2.png -------------------------------------------------------------------------------- /pictures/滑动窗口/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/滑动窗口/3.png -------------------------------------------------------------------------------- /pictures/滑动窗口/title1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/滑动窗口/title1.png -------------------------------------------------------------------------------- /pictures/滑动窗口/title2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/滑动窗口/title2.png -------------------------------------------------------------------------------- /pictures/滑动窗口/title3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/滑动窗口/title3.png -------------------------------------------------------------------------------- /pictures/缺失元素/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/缺失元素/1.jpg -------------------------------------------------------------------------------- /pictures/缺失元素/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/缺失元素/2.jpg -------------------------------------------------------------------------------- /pictures/缺失元素/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/缺失元素/3.jpg -------------------------------------------------------------------------------- /pictures/缺失元素/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/缺失元素/title.png -------------------------------------------------------------------------------- /pictures/缺失元素/xor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/缺失元素/xor.png -------------------------------------------------------------------------------- /pictures/股票问题/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/股票问题/1.png -------------------------------------------------------------------------------- /pictures/股票问题/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/股票问题/title.png -------------------------------------------------------------------------------- /pictures/设计Twitter/design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/设计Twitter/design.png -------------------------------------------------------------------------------- /pictures/设计Twitter/merge.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/设计Twitter/merge.gif -------------------------------------------------------------------------------- /pictures/设计Twitter/tweet.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/设计Twitter/tweet.jpg -------------------------------------------------------------------------------- /pictures/设计Twitter/user.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/pictures/设计Twitter/user.jpg -------------------------------------------------------------------------------- /starHistory.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/starHistory.jpg -------------------------------------------------------------------------------- /starHistory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanveerpot/fucking-algorithm/64d3b3508d7edb7210f6558f37a1f36e95627997/starHistory.png -------------------------------------------------------------------------------- /动态规划系列/LCS.md: -------------------------------------------------------------------------------- 1 | # 详解最长公共子序列问题,秒杀三道动态规划题目 2 | 3 |

4 | GitHub 5 | 6 | 7 | 8 |

9 | 10 | ![](https://labuladong.github.io/pictures/souyisou1.png) 11 | 12 | **通知:[数据结构精品课](https://aep.h5.xeknow.com/s/1XJHEO) 和 [递归算法专题课](https://aep.xet.tech/s/3YGcq3) 限时附赠网站会员,全新纸质书[《labuladong 的算法笔记》](https://labuladong.gitee.io/algo/images/book/book_intro_qrcode.jpg) 出版,签名版限时半价!另外,建议你在我的 [网站](https://labuladong.github.io/algo/) 学习文章,体验更好。** 13 | 14 | 15 | 16 | 读完本文,你不仅学会了算法套路,还可以顺便解决如下题目: 17 | 18 | | LeetCode | 力扣 | 难度 | 19 | | :----: | :----: | :----: | 20 | | [1143. Longest Common Subsequence](https://leetcode.com/problems/longest-common-subsequence/) | [1143. 最长公共子序列](https://leetcode.cn/problems/longest-common-subsequence/) | 🟠 21 | | [583. Delete Operation for Two Strings](https://leetcode.com/problems/delete-operation-for-two-strings/) | [583. 两个字符串的删除操作](https://leetcode.cn/problems/delete-operation-for-two-strings/) | 🟠 22 | | [712. Minimum ASCII Delete Sum for Two Strings](https://leetcode.com/problems/minimum-ascii-delete-sum-for-two-strings/) | [712. 两个字符串的最小ASCII删除和](https://leetcode.cn/problems/minimum-ascii-delete-sum-for-two-strings/) | 🟠 23 | | - | [剑指 Offer II 095. 最长公共子序列](https://leetcode.cn/problems/qJnOS7/) | 🟠 24 | 25 | **-----------** 26 | 27 | 不知道大家做算法题有什么感觉,**我总结出来做算法题的技巧就是,把大的问题细化到一个点,先研究在这个小的点上如何解决问题,然后再通过递归/迭代的方式扩展到整个问题**。 28 | 29 | 比如说我们前文 [手把手带你刷二叉树第三期](https://labuladong.github.io/article/fname.html?fname=二叉树系列3),解决二叉树的题目,我们就会把整个问题细化到某一个节点上,想象自己站在某个节点上,需要做什么,然后套二叉树递归框架就行了。 30 | 31 | 动态规划系列问题也是一样,尤其是子序列相关的问题。**本文从「最长公共子序列问题」展开,总结三道子序列问题**,解这道题仔细讲讲这种子序列问题的套路,你就能感受到这种思维方式了。 32 | 33 | ### 最长公共子序列 34 | 35 | 计算最长公共子序列(Longest Common Subsequence,简称 LCS)是一道经典的动态规划题目,力扣第 1143 题「最长公共子序列」就是这个问题: 36 | 37 | 给你输入两个字符串 `s1` 和 `s2`,请你找出他们俩的最长公共子序列,返回这个子序列的长度。函数签名如下: 38 | 39 | 40 | ```java 41 | int longestCommonSubsequence(String s1, String s2); 42 | ``` 43 | 44 | 比如说输入 `s1 = "zabcde", s2 = "acez"`,它俩的最长公共子序列是 `lcs = "ace"`,长度为 3,所以算法返回 3。 45 | 46 | 如果没有做过这道题,一个最简单的暴力算法就是,把 `s1` 和 `s2` 的所有子序列都穷举出来,然后看看有没有公共的,然后在所有公共子序列里面再寻找一个长度最大的。 47 | 48 | 显然,这种思路的复杂度非常高,你要穷举出所有子序列,这个复杂度就是指数级的,肯定不实际。 49 | 50 | 正确的思路是不要考虑整个字符串,而是细化到 `s1` 和 `s2` 的每个字符。前文 [子序列解题模板](https://labuladong.github.io/article/fname.html?fname=子序列问题模板) 中总结的一个规律: 51 | 52 | 53 | 54 |
55 |
56 | 引用本文的文章 57 | 58 | - [动态规划之子序列问题解题模板](https://labuladong.github.io/article/fname.html?fname=子序列问题模板) 59 | - [经典动态规划:编辑距离](https://labuladong.github.io/article/fname.html?fname=编辑距离) 60 | 61 |

62 | 63 | 64 | 65 | 66 |
67 |
68 | 引用本文的题目 69 | 70 | 安装 [我的 Chrome 刷题插件](https://labuladong.github.io/article/fname.html?fname=chrome插件简介) 点开下列题目可直接查看解题思路: 71 | 72 | | LeetCode | 力扣 | 73 | | :----: | :----: | 74 | | [97. Interleaving String](https://leetcode.com/problems/interleaving-string/?show=1) | [97. 交错字符串](https://leetcode.cn/problems/interleaving-string/?show=1) | 75 | | - | [剑指 Offer II 095. 最长公共子序列](https://leetcode.cn/problems/qJnOS7/?show=1) | 76 | 77 |
78 |
79 | 80 | 81 | 82 | **_____________** 83 | 84 | 本文为会员内容,请扫码关注公众号或 [点这里](https://appktavsiei5995.pc.xiaoe-tech.com/detail/i_6298793ae4b09dda12708be8/1) 查看: 85 | 86 | ![](https://labuladong.github.io/pictures/qrcode.jpg) -------------------------------------------------------------------------------- /动态规划系列/README.md: -------------------------------------------------------------------------------- 1 | # 动态规划系列 2 | 3 | 我们公众号最火的就是动态规划系列的文章,也许是动态规划问题有难度而且有意思,也许因为它是面试常考题型。不管你之前是否害怕动态规划系列的问题,相信这一章的内容足以帮助你消除对动态规划算法的恐惧。 4 | 5 | 具体来说,动态规划的一般流程就是三步:**暴力的递归解法 -> 带备忘录的递归解法 -> 迭代的动态规划解法**。 6 | 7 | 就思考流程来说,就分为一下几步:**找到状态和选择 -> 明确 dp 数组/函数的定义 -> 寻找状态之间的关系**。 8 | 9 | 这就是思维模式的框架,**本章都会按照以上的模式来解决问题,辅助读者养成这种模式思维**,有了方向遇到问题就不会抓瞎,足以解决一般的动态规划问题。 10 | 11 | 欢迎关注我的公众号 labuladong,查看全部文章: 12 | 13 | ![labuladong二维码](../pictures/qrcode.jpg) -------------------------------------------------------------------------------- /动态规划系列/子序列问题模板.md: -------------------------------------------------------------------------------- 1 | # 动态规划之子序列问题解题模板 2 | 3 |

4 | GitHub 5 | 6 | 7 | 8 |

9 | 10 | ![](https://labuladong.github.io/pictures/souyisou1.png) 11 | 12 | **通知:[数据结构精品课](https://aep.h5.xeknow.com/s/1XJHEO) 和 [递归算法专题课](https://aep.xet.tech/s/3YGcq3) 限时附赠网站会员,全新纸质书[《labuladong 的算法笔记》](https://labuladong.gitee.io/algo/images/book/book_intro_qrcode.jpg) 出版,签名版限时半价!另外,建议你在我的 [网站](https://labuladong.github.io/algo/) 学习文章,体验更好。** 13 | 14 | 15 | 16 | 读完本文,你不仅学会了算法套路,还可以顺便解决如下题目: 17 | 18 | | LeetCode | 力扣 | 难度 | 19 | | :----: | :----: | :----: | 20 | | [1312. Minimum Insertion Steps to Make a String Palindrome](https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/) | [1312. 让字符串成为回文串的最少插入次数](https://leetcode.cn/problems/minimum-insertion-steps-to-make-a-string-palindrome/) | 🔴 21 | | [516. Longest Palindromic Subsequence](https://leetcode.com/problems/longest-palindromic-subsequence/) | [516. 最长回文子序列](https://leetcode.cn/problems/longest-palindromic-subsequence/) | 🟠 22 | 23 | **-----------** 24 | 25 | 子序列问题是常见的算法问题,而且并不好解决。 26 | 27 | 首先,子序列问题本身就相对子串、子数组更困难一些,因为前者是不连续的序列,而后两者是连续的,就算穷举你都不一定会,更别说求解相关的算法问题了。 28 | 29 | 而且,子序列问题很可能涉及到两个字符串,比如前文 [最长公共子序列](https://labuladong.github.io/article/fname.html?fname=LCS),如果没有一定的处理经验,真的不容易想出来。所以本文就来扒一扒子序列问题的套路,其实就有两种模板,相关问题只要往这两种思路上想,十拿九稳。 30 | 31 | 一般来说,这类问题都是让你求一个**最长子序列**,因为最短子序列就是一个字符嘛,没啥可问的。一旦涉及到子序列和最值,那几乎可以肯定,**考察的是动态规划技巧,时间复杂度一般都是 O(n^2)**。 32 | 33 | 原因很简单,你想想一个字符串,它的子序列有多少种可能?起码是指数级的吧,这种情况下,不用动态规划技巧,还想怎么着? 34 | 35 | 既然要用动态规划,那就要定义 `dp` 数组,找状态转移关系。我们说的两种思路模板,就是 `dp` 数组的定义思路。不同的问题可能需要不同的 `dp` 数组定义来解决。 36 | 37 | ### 一、两种思路 38 | 39 | 40 | 41 |
42 |
43 | 引用本文的文章 44 | 45 | - [动态规划设计:最长递增子序列](https://labuladong.github.io/article/fname.html?fname=动态规划设计:最长递增子序列) 46 | - [如何判断回文链表](https://labuladong.github.io/article/fname.html?fname=判断回文链表) 47 | - [对动态规划进行降维打击](https://labuladong.github.io/article/fname.html?fname=状态压缩技巧) 48 | - [最优子结构原理和 dp 数组遍历方向](https://labuladong.github.io/article/fname.html?fname=最优子结构) 49 | - [经典动态规划:最长公共子序列](https://labuladong.github.io/article/fname.html?fname=LCS) 50 | 51 |

52 | 53 | 54 | 55 | 56 | 57 | **_____________** 58 | 59 | 本文为会员内容,请扫码关注公众号或 [点这里](https://appktavsiei5995.pc.xiaoe-tech.com/detail/i_62987943e4b01c509ab8b6aa/1) 查看: 60 | 61 | ![](https://labuladong.github.io/pictures/qrcode.jpg) 62 | 63 | ======其他语言代码====== 64 | 65 | [516.最长回文子序列](https://leetcode-cn.com/problems/longest-palindromic-subsequence) 66 | 67 | ### javascript 68 | 69 | ```js 70 | /** 71 | * @param {string} s 72 | * @return {number} 73 | */ 74 | var longestPalindromeSubseq = function (s) { 75 | let l = s.length; 76 | if (l <= 1) { 77 | return l; 78 | } 79 | 80 | // 初始化一个 dp[l][l] 81 | let dp = new Array(l); 82 | for (let i = 0; i < l; i++) { 83 | dp[i] = new Array(l); 84 | dp[i].fill(0, 0, l) 85 | // // base case 86 | dp[i][i] = 1 87 | } 88 | 89 | // 从右下角开始,逐渐往上推 90 | for (let i = l - 2; i >= 0; i--) { 91 | for (let j = i + 1; j <= l - 1; j++) { 92 | if (s[i] === s[j]) { 93 | dp[i][j] = dp[i + 1][j - 1] + 2; 94 | } else { 95 | dp[i][j] = Math.max( 96 | dp[i + 1][j], 97 | dp[i][j - 1] 98 | ) 99 | } 100 | } 101 | } 102 | return dp[0][l - 1] 103 | }; 104 | ``` 105 | 106 | -------------------------------------------------------------------------------- /动态规划系列/背包问题.md: -------------------------------------------------------------------------------- 1 | # 动态规划之背包问题 2 | 3 |

4 | GitHub 5 | 6 | 7 | 8 |

9 | 10 | ![](https://labuladong.github.io/pictures/souyisou1.png) 11 | 12 | **通知:[数据结构精品课](https://aep.h5.xeknow.com/s/1XJHEO) 和 [递归算法专题课](https://aep.xet.tech/s/3YGcq3) 限时附赠网站会员,全新纸质书[《labuladong 的算法笔记》](https://labuladong.gitee.io/algo/images/book/book_intro_qrcode.jpg) 出版,签名版限时半价!另外,建议你在我的 [网站](https://labuladong.github.io/algo/) 学习文章,体验更好。** 13 | 14 | 15 | 16 | **-----------** 17 | 18 | > tip:本文有视频版:[0-1背包问题详解](https://www.bilibili.com/video/BV15B4y1P7X7/)。建议关注我的 B 站账号,我会用视频领读的方式带大家学习那些稍有难度的算法技巧。 19 | 20 | 21 | 22 | 后台天天有人问背包问题,这个问题其实不难啊,如果我们号动态规划系列的十几篇文章你都看过,借助框架,遇到背包问题可以说是手到擒来好吧。无非就是状态 + 选择,也没啥特别之处嘛。 23 | 24 | 今天就来说一下背包问题吧,就讨论最常说的 0-1 背包问题。描述: 25 | 26 | 给你一个可装载重量为 `W` 的背包和 `N` 个物品,每个物品有重量和价值两个属性。其中第 `i` 个物品的重量为 `wt[i]`,价值为 `val[i]`,现在让你用这个背包装物品,最多能装的价值是多少? 27 | 28 | ![](https://labuladong.github.io/pictures/knapsack/1.png) 29 | 30 | 举个简单的例子,输入如下: 31 | 32 | ```py 33 | N = 3, W = 4 34 | wt = [2, 1, 3] 35 | val = [4, 2, 3] 36 | ``` 37 | 38 | 算法返回 6,选择前两件物品装进背包,总重量 3 小于 `W`,可以获得最大价值 6。 39 | 40 | 题目就是这么简单,一个典型的动态规划问题。这个题目中的物品不可以分割,要么装进包里,要么不装,不能说切成两块装一半。这就是 0-1 背包这个名词的来历。 41 | 42 | 解决这个问题没有什么排序之类巧妙的方法,只能穷举所有可能,根据我们 [动态规划详解](https://labuladong.github.io/article/fname.html?fname=动态规划详解进阶) 中的套路,直接走流程就行了。 43 | 44 | ### 动规标准套路 45 | 46 | 看来每篇动态规划文章都得重复一遍套路,历史文章中的动态规划问题都是按照下面的套路来的。 47 | 48 | **第一步要明确两点,「状态」和「选择」**。 49 | 50 | 先说状态,如何才能描述一个问题局面?只要给几个物品和一个背包的容量限制,就形成了一个背包问题呀。**所以状态有两个,就是「背包的容量」和「可选择的物品」**。 51 | 52 | 再说选择,也很容易想到啊,对于每件物品,你能选择什么?**选择就是「装进背包」或者「不装进背包」嘛**。 53 | 54 | 明白了状态和选择,动态规划问题基本上就解决了,只要往这个框架套就完事儿了: 55 | 56 | ```python 57 | for 状态1 in 状态1的所有取值: 58 | for 状态2 in 状态2的所有取值: 59 | for ... 60 | dp[状态1][状态2][...] = 择优(选择1,选择2...) 61 | ``` 62 | 63 | > tip:此框架出自历史文章 [团灭 LeetCode 股票问题](https://labuladong.github.io/article/fname.html?fname=团灭股票问题)。 64 | 65 | **第二步要明确 `dp` 数组的定义**。 66 | 67 | 首先看看刚才找到的「状态」,有两个,也就是说我们需要一个二维 `dp` 数组。 68 | 69 | `dp[i][w]` 的定义如下:对于前 `i` 个物品,当前背包的容量为 `w`,这种情况下可以装的最大价值是 `dp[i][w]`。 70 | 71 | 比如说,如果 `dp[3][5] = 6`,其含义为:对于给定的一系列物品中,若只对前 3 个物品进行选择,当背包容量为 5 时,最多可以装下的价值为 6。 72 | 73 | > info:为什么要这么定义?便于状态转移,或者说这就是套路,记下来就行了。建议看一下我们的动态规划系列文章,几种套路都被扒得清清楚楚了。 74 | 75 | 根据这个定义,我们想求的最终答案就是 `dp[N][W]`。base case 就是 `dp[0][..] = dp[..][0] = 0`,因为没有物品或者背包没有空间的时候,能装的最大价值就是 0。 76 | 77 | 细化上面的框架: 78 | 79 | ```python 80 | int[][] dp[N+1][W+1] 81 | dp[0][..] = 0 82 | dp[..][0] = 0 83 | 84 | for i in [1..N]: 85 | for w in [1..W]: 86 | dp[i][w] = max( 87 | 把物品 i 装进背包, 88 | 不把物品 i 装进背包 89 | ) 90 | return dp[N][W] 91 | ``` 92 | 93 | **第三步,根据「选择」,思考状态转移的逻辑**。 94 | 95 | 简单说就是,上面伪码中「把物品 `i` 装进背包」和「不把物品 `i` 装进背包」怎么用代码体现出来呢? 96 | 97 | 这就要结合对 `dp` 数组的定义,看看这两种选择会对状态产生什么影响: 98 | 99 | 先重申一下刚才我们的 `dp` 数组的定义: 100 | 101 | `dp[i][w]` 表示:对于前 `i` 个物品(从 1 开始计数),当前背包的容量为 `w` 时,这种情况下可以装下的最大价值是 `dp[i][w]`。 102 | 103 | **如果你没有把这第 `i` 个物品装入背包**,那么很显然,最大价值 `dp[i][w]` 应该等于 `dp[i-1][w]`,继承之前的结果。 104 | 105 | **如果你把这第 `i` 个物品装入了背包**,那么 `dp[i][w]` 应该等于 `val[i-1] + dp[i-1][w - wt[i-1]]`。 106 | 107 | 首先,由于数组索引从 0 开始,而我们定义中的 `i` 是从 1 开始计数的,所以 `val[i-1]` 和 `wt[i-1]` 表示第 `i` 个物品的价值和重量。 108 | 109 | 你如果选择将第 `i` 个物品装进背包,那么第 `i` 个物品的价值 `val[i-1]` 肯定就到手了,接下来你就要在剩余容量 `w - wt[i-1]` 的限制下,在前 `i - 1` 个物品中挑选,求最大价值,即 `dp[i-1][w - wt[i-1]]`。 110 | 111 | 综上就是两种选择,我们都已经分析完毕,也就是写出来了状态转移方程,可以进一步细化代码: 112 | 113 | ```python 114 | for i in [1..N]: 115 | for w in [1..W]: 116 | dp[i][w] = max( 117 | dp[i-1][w], 118 | dp[i-1][w - wt[i-1]] + val[i-1] 119 | ) 120 | return dp[N][W] 121 | ``` 122 | 123 | **最后一步,把伪码翻译成代码,处理一些边界情况**。 124 | 125 | 我用 Java 写的代码,把上面的思路完全翻译了一遍,并且处理了 `w - wt[i-1]` 可能小于 0 导致数组索引越界的问题: 126 | 127 | 128 | ```java 129 | int knapsack(int W, int N, int[] wt, int[] val) { 130 | assert N == wt.length; 131 | // base case 已初始化 132 | int[][] dp = new int[N + 1][W + 1]; 133 | for (int i = 1; i <= N; i++) { 134 | for (int w = 1; w <= W; w++) { 135 | if (w - wt[i - 1] < 0) { 136 | // 这种情况下只能选择不装入背包 137 | dp[i][w] = dp[i - 1][w]; 138 | } else { 139 | // 装入或者不装入背包,择优 140 | dp[i][w] = Math.max( 141 | dp[i - 1][w - wt[i-1]] + val[i-1], 142 | dp[i - 1][w] 143 | ); 144 | } 145 | } 146 | } 147 | 148 | return dp[N][W]; 149 | } 150 | ``` 151 | 152 | 153 | 154 | > note:其实函数签名中的物品数量 `N` 就是 `wt` 数组的长度,所以实际上这个参数 `N` 是多此一举的。但为了体现原汁原味的 0-1 背包问题,我就带上这个参数 `N` 了,你自己写的话可以省略。 155 | 156 | 至此,背包问题就解决了,相比而言,我觉得这是比较简单的动态规划问题,因为状态转移的推导比较自然,基本上你明确了 `dp` 数组的定义,就可以理所当然地确定状态转移了。 157 | 158 | 接下来可阅读: 159 | 160 | * [完全背包问题之零钱兑换](https://labuladong.github.io/article/fname.html?fname=背包零钱) 161 | * [背包问题变体之子集分割](https://labuladong.github.io/article/fname.html?fname=背包子集) 162 | 163 | 164 | 165 |
166 |
167 | 引用本文的文章 168 | 169 | - [回溯算法穷举的两种视角](https://labuladong.github.io/article/fname.html?fname=集合划分) 170 | - [扫描线技巧:安排会议室](https://labuladong.github.io/article/fname.html?fname=安排会议室) 171 | - [目标和:背包问题的变体](https://labuladong.github.io/article/fname.html?fname=targetSum) 172 | - [经典动态规划:子集背包问题](https://labuladong.github.io/article/fname.html?fname=背包子集) 173 | - [经典动态规划:完全背包问题](https://labuladong.github.io/article/fname.html?fname=背包零钱) 174 | 175 |

176 | 177 | 178 | 179 | 180 | 181 | **_____________** 182 | 183 | **《labuladong 的算法小抄》已经出版,关注公众号查看详情;后台回复「**全家桶**」可下载配套 PDF 和刷题全家桶**: 184 | 185 | ![](https://labuladong.github.io/pictures/souyisou2.png) -------------------------------------------------------------------------------- /动态规划系列/贪心算法之区间调度问题.md: -------------------------------------------------------------------------------- 1 | # 贪心算法之区间调度问题 2 | 3 |

4 | GitHub 5 | 6 | 7 | 8 |

9 | 10 | ![](https://labuladong.github.io/pictures/souyisou1.png) 11 | 12 | **通知:[数据结构精品课](https://aep.h5.xeknow.com/s/1XJHEO) 和 [递归算法专题课](https://aep.xet.tech/s/3YGcq3) 限时附赠网站会员,全新纸质书[《labuladong 的算法笔记》](https://labuladong.gitee.io/algo/images/book/book_intro_qrcode.jpg) 出版,签名版限时半价!另外,建议你在我的 [网站](https://labuladong.github.io/algo/) 学习文章,体验更好。** 13 | 14 | 15 | 16 | 读完本文,你不仅学会了算法套路,还可以顺便解决如下题目: 17 | 18 | | LeetCode | 力扣 | 难度 | 19 | | :----: | :----: | :----: | 20 | | [435. Non-overlapping Intervals](https://leetcode.com/problems/non-overlapping-intervals/) | [435. 无重叠区间](https://leetcode.cn/problems/non-overlapping-intervals/) | 🟠 21 | | [452. Minimum Number of Arrows to Burst Balloons](https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/) | [452. 用最少数量的箭引爆气球](https://leetcode.cn/problems/minimum-number-of-arrows-to-burst-balloons/) | 🟠 22 | 23 | **-----------** 24 | 25 | 什么是贪心算法呢?贪心算法可以认为是动态规划算法的一个特例,相比动态规划,使用贪心算法需要满足更多的条件(贪心选择性质),但是效率比动态规划要高。 26 | 27 | 比如说一个算法问题使用暴力解法需要指数级时间,如果能使用动态规划消除重叠子问题,就可以降到多项式级别的时间,如果满足贪心选择性质,那么可以进一步降低时间复杂度,达到线性级别的。 28 | 29 | 什么是贪心选择性质呢,简单说就是:每一步都做出一个局部最优的选择,最终的结果就是全局最优。注意哦,这是一种特殊性质,其实只有一部分问题拥有这个性质。 30 | 31 | 比如你面前放着 100 张人民币,你只能拿十张,怎么才能拿最多的面额?显然每次选择剩下钞票中面值最大的一张,最后你的选择一定是最优的。 32 | 33 | 然而,大部分问题明显不具有贪心选择性质。比如打斗地主,对手出对儿三,按照贪心策略,你应该出尽可能小的牌刚好压制住对方,但现实情况我们甚至可能会出王炸。这种情况就不能用贪心算法,而得使用动态规划解决,参见前文 [动态规划解决博弈问题](https://labuladong.github.io/article/fname.html?fname=动态规划之博弈问题)。 34 | 35 | ### 一、问题概述 36 | 37 | 言归正传,本文解决一个很经典的贪心算法问题 Interval Scheduling(区间调度问题),也就是力扣第 435 题「无重叠区间」: 38 | 39 | 给你很多形如 `[start, end]` 的闭区间,请你设计一个算法,**算出这些区间中最多有几个互不相交的区间**。 40 | 41 | 42 | ```java 43 | int intervalSchedule(int[][] intvs); 44 | ``` 45 | 46 | 举个例子,`intvs = [[1,3], [2,4], [3,6]]`,这些区间最多有 2 个区间互不相交,即 `[[1,3], [3,6]]`,你的算法应该返回 2。注意边界相同并不算相交。 47 | 48 | 这个问题在生活中的应用广泛,比如你今天有好几个活动,每个活动都可以用区间 `[start, end]` 表示开始和结束的时间,请问你今天**最多能参加几个活动呢**?显然你一个人不能同时参加两个活动,所以说这个问题就是求这些时间区间的最大不相交子集。 49 | 50 | 51 | 52 |
53 |
54 | 引用本文的文章 55 | 56 | - [一个方法解决三道区间问题](https://labuladong.github.io/article/fname.html?fname=区间问题合集) 57 | - [分治算法详解:运算优先级](https://labuladong.github.io/article/fname.html?fname=分治算法) 58 | - [剪视频剪出一个贪心算法](https://labuladong.github.io/article/fname.html?fname=剪视频) 59 | - [如何运用贪心思想玩跳跃游戏](https://labuladong.github.io/article/fname.html?fname=跳跃游戏) 60 | - [扫描线技巧:安排会议室](https://labuladong.github.io/article/fname.html?fname=安排会议室) 61 | 62 |

63 | 64 | 65 | 66 | 67 | 68 | **_____________** 69 | 70 | 本文为会员内容,请扫码关注公众号或 [点这里](https://appktavsiei5995.pc.xiaoe-tech.com/detail/i_649bf3aee4b09d72379e4576/1) 查看: 71 | 72 | ![](https://labuladong.github.io/pictures/qrcode.jpg) 73 | 74 | ======其他语言代码====== 75 | 76 | [435. 无重叠区间](https://leetcode-cn.com/problems/non-overlapping-intervals/) 77 | 78 | [452.用最少数量的箭引爆气球](https://leetcode-cn.com/problems/minimum-number-of-arrows-to-burst-balloons) 79 | 80 | ### python 81 | Edwenc 提供 第435题的python3 代码: 82 | 83 | ```python 84 | class Solution: 85 | def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int: 86 | ### 思路是首先找到不重叠的区间的个数 87 | ### 然后再用总个数减去不重叠个数 88 | ### 获得的就是 需要移除的个数 89 | 90 | # 首先获得区间的个数 为0的话就不用移除 91 | n = len(intervals) 92 | if n==0: 93 | return 0 94 | 95 | # 按照每个区间的右端点值进行排序 96 | sorted_list = sorted( intervals , key=lambda x: x[1] ) 97 | 98 | # 不重叠区间个数至少是1 99 | count = 1 100 | 101 | # end是所有不重叠的区间中 最大的右端点 102 | # end的初始值即是sorted_list[0]的右端点 103 | end = sorted_list[0][1] 104 | 105 | # 从1开始往后找 因为0在上面已经取过了 106 | for i in range(1,n): 107 | # start是当前区间左端点值 108 | start = sorted_list[i][0] 109 | # 如果当前左端点比最大右端点都大了(可能相等) 110 | # 说明两区间不重叠 count+1 再更新end 111 | if start>=end: 112 | count += 1 113 | end = sorted_list[i][1] 114 | 115 | # 最后返回的是 需要移除的区间个数 116 | return n-count 117 | ``` 118 | 119 | 120 | 121 | ### javascript 122 | 123 | **区间调度实现** 124 | 125 | ```js 126 | var intervalSchedule = function (intvs) { 127 | if (intvs.length === 0) return 0; 128 | // 按end升序排序 129 | intvs.sort((a, b) => { 130 | if (a[1] < b[1]) 131 | return -1; 132 | else if (a[1] > b[1]) 133 | return 1; 134 | else return 0; 135 | }) 136 | 137 | // 至少有一个区间不相交 138 | let count = 1; 139 | 140 | // 排序后,第一个区间就是 x 141 | let x_end = intvs[0][1]; 142 | for (let interval of intvs) { 143 | let start = interval[0]; 144 | if (start >= x_end) { 145 | // 找到下一个选择的区间了 146 | count++; 147 | x_end = interval[1]; 148 | } 149 | } 150 | return count; 151 | } 152 | ``` 153 | 154 | **第435题 无重叠区间** 155 | 156 | ```js 157 | /** 158 | * @param {number[][]} intervals 159 | * @return {number} 160 | */ 161 | var eraseOverlapIntervals = function (intervals) { 162 | let n = intervals.length; 163 | // 我们已经会求最多有几个区间不会重叠了,那么剩下的不就是至少需要去除的区间吗? 164 | return n - intervalSchedule(intervals); 165 | }; 166 | 167 | var intervalSchedule = function (intvs) { 168 | if (intvs.length === 0) return 0; 169 | // 按end升序排序 170 | intvs.sort((a, b) => { 171 | if (a[1] < b[1]) 172 | return -1; 173 | else if (a[1] > b[1]) 174 | return 1; 175 | else return 0; 176 | }) 177 | 178 | // 至少有一个区间不相交 179 | let count = 1; 180 | 181 | // 排序后,第一个区间就是 x 182 | let x_end = intvs[0][1]; 183 | for (let interval of intvs) { 184 | let start = interval[0]; 185 | if (start >= x_end) { 186 | // 找到下一个选择的区间了 187 | count++; 188 | x_end = interval[1]; 189 | } 190 | } 191 | return count; 192 | } 193 | ``` 194 | 195 | **第452题 用最少数量的箭引爆气球** 196 | 197 | ```js 198 | /** 199 | * @param {number[][]} points 200 | * @return {number} 201 | */ 202 | var findMinArrowShots = function (intvs) { 203 | if (intvs.length === 0) return 0; 204 | // 按end升序排序 205 | intvs.sort((a, b) => { 206 | if (a[1] < b[1]) 207 | return -1; 208 | else if (a[1] > b[1]) 209 | return 1; 210 | else return 0; 211 | }) 212 | 213 | // 至少有一个区间不相交 214 | let count = 1; 215 | 216 | // 排序后,第一个区间就是 x 217 | let x_end = intvs[0][1]; 218 | for (let interval of intvs) { 219 | let start = interval[0]; 220 | if (start > x_end) { 221 | // 找到下一个选择的区间了 222 | count++; 223 | x_end = interval[1]; 224 | } 225 | } 226 | return count; 227 | }; 228 | ``` 229 | 230 | -------------------------------------------------------------------------------- /动态规划系列/高楼扔鸡蛋问题.md: -------------------------------------------------------------------------------- 1 | # 经典动态规划问题:高楼扔鸡蛋 2 | 3 |

4 | GitHub 5 | 6 | 7 | 8 |

9 | 10 | ![](https://labuladong.github.io/pictures/souyisou1.png) 11 | 12 | **通知:[数据结构精品课](https://aep.h5.xeknow.com/s/1XJHEO) 和 [递归算法专题课](https://aep.xet.tech/s/3YGcq3) 限时附赠网站会员,全新纸质书[《labuladong 的算法笔记》](https://labuladong.gitee.io/algo/images/book/book_intro_qrcode.jpg) 出版,签名版限时半价!另外,建议你在我的 [网站](https://labuladong.github.io/algo/) 学习文章,体验更好。** 13 | 14 | 15 | 16 | 读完本文,你不仅学会了算法套路,还可以顺便解决如下题目: 17 | 18 | | LeetCode | 力扣 | 难度 | 19 | | :----: | :----: | :----: | 20 | | [887. Super Egg Drop](https://leetcode.com/problems/super-egg-drop/) | [887. 鸡蛋掉落](https://leetcode.cn/problems/super-egg-drop/) | 🔴 21 | 22 | **-----------** 23 | 24 | 本文要聊一个很经典的算法问题,若干层楼,若干个鸡蛋,让你算出最少的尝试次数,找到鸡蛋恰好摔不碎的那层楼。国内大厂以及谷歌脸书面试都经常考察这道题,只不过他们觉得扔鸡蛋太浪费,改成扔杯子,扔破碗什么的。 25 | 26 | 具体的问题等会再说,但是这道题的解法技巧很多,光动态规划就好几种效率不同的思路,最后还有一种极其高效数学解法。秉承本书一贯的作风,拒绝过于诡异的技巧,因为这些技巧无法举一反三,学了也不划算。 27 | 28 | 下面就来用我们一直强调的动态规划通用思路来研究一下这道题。 29 | 30 | ### 一、解析题目 31 | 32 | 这是力扣第 887 题「鸡蛋掉落」,我描述一下题目: 33 | 34 | 你面前有一栋从 1 到 `N` 共 `N` 层的楼,然后给你 `K` 个鸡蛋(`K` 至少为 1)。现在确定这栋楼存在楼层 `0 <= F <= N`,在这层楼将鸡蛋扔下去,鸡蛋**恰好没摔碎**(高于 `F` 的楼层都会碎,低于 `F` 的楼层都不会碎,如果鸡蛋没有碎,可以捡回来继续扔)。现在问你,**最坏**情况下,你**至少**要扔几次鸡蛋,才能**确定**这个楼层 `F` 呢? 35 | 36 | 也就是让你找摔不碎鸡蛋的最高楼层 `F`,但什么叫「最坏情况」下「至少」要扔几次呢?我们分别举个例子就明白了。 37 | 38 | 比方说**现在先不管鸡蛋个数的限制**,有 7 层楼,你怎么去找鸡蛋恰好摔碎的那层楼? 39 | 40 | 最原始的方式就是线性扫描:我先在 1 楼扔一下,没碎,我再去 2 楼扔一下,没碎,我再去 3 楼…… 41 | 42 | 以这种策略,**最坏**情况应该就是我试到第 7 层鸡蛋也没碎(`F = 7`),也就是我扔了 7 次鸡蛋。 43 | 44 | 先在你应该理解什么叫做「最坏情况」下了,**鸡蛋破碎一定发生在搜索区间穷尽时**,不会说你在第 1 层摔一下鸡蛋就碎了,这是你运气好,不是最坏情况。 45 | 46 | 现在再来理解一下什么叫「至少」要扔几次。依然不考虑鸡蛋个数限制,同样是 7 层楼,我们可以优化策略。 47 | 48 | 最好的策略是使用二分查找思路,我先去第 `(1 + 7) / 2 = 4` 层扔一下: 49 | 50 | 如果碎了说明 `F` 小于 4,我就去第 `(1 + 3) / 2 = 2` 层试…… 51 | 52 | 如果没碎说明 `F` 大于等于 4,我就去第 `(5 + 7) / 2 = 6` 层试…… 53 | 54 | 以这种策略,**最坏**情况应该是试到第 7 层鸡蛋还没碎(`F = 7`),或者鸡蛋一直碎到第 1 层(`F = 0`)。然而无论那种最坏情况,只需要试 `log7` 向上取整等于 3 次,比刚才尝试 7 次要少,这就是所谓的**至少**要扔几次。 55 | 56 | 实际上,如果不限制鸡蛋个数的话,二分思路显然可以得到最少尝试的次数,但问题是,**现在给你了鸡蛋个数的限制 `K`,直接使用二分思路就不行了**。 57 | 58 | 比如说只给你 1 个鸡蛋,7 层楼,你敢用二分吗?你直接去第 4 层扔一下,如果鸡蛋没碎还好,你可以把鸡蛋捡起来再去更高的楼层尝试;但如果碎了,你就没有鸡蛋继续测试了,无法确定鸡蛋恰好摔不碎的楼层 `F` 了。 59 | 60 | 其实这种情况下只能用线性扫描的方法,从下网上一层层尝试扔鸡蛋,那么最坏情况下需要扔 7 次,算法返回结果应该是 7。 61 | 62 | 有的读者也许会有这种想法:二分查找排除楼层的速度无疑是最快的,那干脆先用二分查找,等到只剩 1 个鸡蛋的时候再执行线性扫描,这样得到的结果是不是就是最少的扔鸡蛋次数呢? 63 | 64 | 很遗憾,并不是,比如说把楼层变高一些,100 层,给你 2 个鸡蛋,你在 50 层扔一下,碎了,那就只能线性扫描 1~49 层了,最坏情况下要扔 50 次。 65 | 66 | 如果不要「二分」,变成「五分」「十分」都会大幅减少最坏情况下的尝试次数。比方说第一个鸡蛋每隔十层楼扔,在哪里碎了第二个鸡蛋一个个线性扫描,总共不会超过 20 次。最优解其实是 14 次。最优策略非常多,而且并没有什么规律可言。 67 | 68 | 说了这么多废话,就是确保大家理解了题目的意思,而且认识到这个题目确实复杂,就连我们手算都不容易,如何用算法解决呢? 69 | 70 | 71 | 72 |
73 |
74 | 引用本文的文章 75 | 76 | - [二分搜索怎么用?我又总结了套路](https://labuladong.github.io/article/fname.html?fname=二分运用) 77 | - [动态规划穷举的两种视角](https://labuladong.github.io/article/fname.html?fname=动归两种视角) 78 | - [最优子结构原理和 dp 数组遍历方向](https://labuladong.github.io/article/fname.html?fname=最优子结构) 79 | - [经典动态规划:戳气球](https://labuladong.github.io/article/fname.html?fname=扎气球) 80 | 81 |

82 | 83 | 84 | 85 | 86 | 87 | **_____________** 88 | 89 | 本文为会员内容,请扫码关注公众号或 [点这里](https://appktavsiei5995.pc.xiaoe-tech.com/detail/i_6298795de4b01a4852072fa7/1) 查看: 90 | 91 | ![](https://labuladong.github.io/pictures/qrcode.jpg) 92 | 93 | ======其他语言代码====== 94 | 95 | [887.鸡蛋掉落](https://leetcode-cn.com/problems/super-egg-drop/) 96 | 97 | ### javascript 98 | 99 | **dp状态转移 + 备忘录** 100 | 101 | ```js 102 | var superEggDrop = function (K, N) { 103 | let memo = {} 104 | 105 | let dp = function (K, N) { 106 | // base case 107 | if (K === 1) return N; 108 | if (N === 0) return 0; 109 | 110 | // 避免重复计算 111 | let key = K + ',' + N 112 | if (memo[key] !== undefined) { 113 | return memo[key]; 114 | } 115 | 116 | // 正无穷 117 | let res = Infinity; 118 | 119 | // 穷举所有的可能的选择 120 | for (let i = 1; i < N + 1; i++) { 121 | res = Math.min( 122 | res, 123 | Math.max( 124 | dp(K, N - i), 125 | dp(K - 1, i - 1) 126 | ) + 1 127 | ) 128 | } 129 | 130 | // 记入备忘录 131 | memo[key] = res; 132 | return res; 133 | } 134 | 135 | return dp(K, N); 136 | }; 137 | ``` 138 | 139 | 140 | 141 | **dp状态转移 + 备忘录 + 二分法** 142 | 143 | ```js 144 | var superEggDrop = function (K, N) { 145 | let memo = {} 146 | 147 | let dp = function (K, N) { 148 | // base case 149 | if (K === 1) return N; 150 | if (N === 0) return 0; 151 | 152 | // 避免重复计算 153 | let key = K + ',' + N 154 | if (memo[key] !== undefined) { 155 | return memo[key]; 156 | } 157 | 158 | // 正无穷 159 | let res = Infinity; 160 | 161 | // 穷举所有的可能的选择 162 | // for (let i = 1; i < N + 1; i++) { 163 | // res = Math.min( 164 | // res, 165 | // Math.max( 166 | // dp(K, N - i), 167 | // dp(K - 1, i - 1) 168 | // ) + 1 169 | // ) 170 | // } 171 | 172 | // 用二分搜索代替线性搜索 173 | let lo = 1, hi = N; 174 | while (lo <= hi) { 175 | let mid = Math.floor((lo + hi) / 2); 176 | let broken = dp(K - 1, mid - 1) // 碎 177 | let not_broken = dp(K, N - mid) // 没碎 178 | 179 | // res = min(max(碎,没碎) + 1) 180 | if (broken > not_broken) { 181 | hi = mid - 1 182 | res = Math.min(res, broken + 1) 183 | } else { 184 | lo = mid + 1 185 | res = Math.min(res, not_broken + 1) 186 | } 187 | } 188 | 189 | 190 | // 记入备忘录 191 | memo[key] = res; 192 | return res; 193 | } 194 | 195 | return dp(K, N); 196 | }; 197 | 198 | ``` 199 | 200 | -------------------------------------------------------------------------------- /多语言解法代码/contribution-guide.md: -------------------------------------------------------------------------------- 1 | # 修正 labuladong 刷题插件中的错误 2 | 3 | ## 背景 4 | 5 | 为了帮助大家更好地学习算法,我之前写了很多算法教程,并开发了一系列刷题插件,统称为《labuladong 的刷题全家桶》,详情见 [这里](https://labuladong.github.io/article/fname.html?fname=全家桶简介)。 6 | 7 | 在我的教程和插件中的解法主要使用的是 Java 语言,原因是 Java 这门语言中规中矩,就算之前没有接触过,也能比较容易看懂逻辑。不过现在这不是 chatGPT 横空出世了嘛,我就借助 chatGPT 把我的解法改写成多种语言,希望对不同技术背景的小伙伴更加友好。 8 | 9 | chatGPT 的改写效果还是非常不错的,不过难免还是存在一些错误,所以我希望能够和大家一起来修正这些错误。 10 | 11 | ## 如何反馈错误 12 | 13 | 如果你发现某些解法代码不能通过力扣的所有测试用例(一般都是 chatGPT 改写的解法代码会出现这种情况,我的解法代码都是通过测试才发布的),可以 [点这里](https://github.com/labuladong/fucking-algorithm/issues/new?assignees=&labels=code+bug&template=bug_report.yml&title=%5Bbug%5D%5B%7B%E8%BF%99%E9%87%8C%E6%9B%BF%E6%8D%A2%E4%B8%BA%E5%87%BA%E9%94%99%E7%9A%84%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80%7D%5D+%7B%E8%BF%99%E9%87%8C%E6%9B%BF%E6%8D%A2%E4%B8%BA%E5%87%BA%E9%94%99%E7%9A%84%E5%8A%9B%E6%89%A3%E9%A2%98%E7%9B%AE%E6%A0%87%E8%AF%86%E7%AC%A6%7D+) 按照模板提交 issue,我和其他小伙伴会提交 PR 修复这些错误。 14 | 15 | ## 如何修正错误 16 | 17 | 首先,感谢你愿意为我的插件提供的解法代码纠错,你向本仓库提交 PR 修复错误后,你将成为本仓库的 contributor,出现在仓库首页的贡献者列表中。本仓库已经获得了 115k star,你的贡献将会被许多人看到。 18 | 19 | 修复代码很简单,所有多语言解法代码都存储在 [多语言解法代码/solution_code.md](https://github.com/labuladong/fucking-algorithm/blob/master/%E5%A4%9A%E8%AF%AD%E8%A8%80%E8%A7%A3%E6%B3%95%E4%BB%A3%E7%A0%81/solution_code.md) 中,你只要修改这个文件就行了。其内容的组织形如如下: 20 | 21 | 22 | https://leetcode.cn/problems/xxx 的多语言解法👇 23 | 24 | ```cpp 25 | class Solution { 26 | public: 27 | int xxx() { 28 | // ... 29 | } 30 | }; 31 | ``` 32 | 33 | ```java 34 | class Solution { 35 | public int xxx() { 36 | // ... 37 | } 38 | } 39 | ``` 40 | 41 | ```python 42 | class Solution: 43 | def xxx(self): 44 | # ... 45 | ``` 46 | 47 | ```javascript 48 | var xxx = function() { 49 | // ... 50 | } 51 | ``` 52 | 53 | ```go 54 | func xxx() { 55 | // ... 56 | } 57 | ``` 58 | 59 | https://leetcode.cn/problems/xxx 的多语言解法👆 60 | 61 | 62 | 比如你想修改 [https://leetcode-cn.com/problems/longest-palindromic-substring/](https://leetcode-cn.com/problems/longest-palindromic-substring/) 的 JavaScript 解法,你可以在 [多语言解法代码/solution_code.md](https://github.com/labuladong/fucking-algorithm/blob/master/%E5%A4%9A%E8%AF%AD%E8%A8%80%E8%A7%A3%E6%B3%95%E4%BB%A3%E7%A0%81/solution_code.md) 中搜索 `longest-palindromic-substring` 关键词,即可找到这道题的多语言解法,然后修改 JavaScript 对应的解法代码,提交 PR 即可。 63 | 64 | 我的插件会自动拉取这个文件的最新内容,所以你的 PR 被合进 master 分支后,插件中的内容修改也会生效。 65 | 66 | ## 提交 PR 的要求 67 | 68 | 1、你的 PR 必须是针对 [多语言解法代码/solution_code.md](https://github.com/labuladong/fucking-algorithm/blob/master/%E5%A4%9A%E8%AF%AD%E8%A8%80%E8%A7%A3%E6%B3%95%E4%BB%A3%E7%A0%81/solution_code.md) 文件中代码部分的修改,不要修改其他文件和其他内容。 69 | 70 | 2、把我的解法翻译成多语言的目的是帮助不同背景的小伙伴理解算法思维,所以你修改的代码可以不是效率最优的,但应该尽可能和我的解法思路保持一致,且包含我的解法中的完整注释。 71 | 72 | 3、你的 PR 描述中需要包含代码通过所有测试用例截图。PR 标题的格式为 `[fix][{lang}] {slug}`,其中 `{lang}` 需要替换为你修复的解法语言,比如 `[fix][cpp]`,`{slug}` 需要替换为你修复的题目的标识符(题目 URL 的最后一部分),比如 [https://leetcode.cn/problems/search-a-2d-matrix/](https://leetcode.cn/problems/search-a-2d-matrix/) 这道题的标识符就是 `search-a-2d-matrix`。 73 | 74 | **你可以查看这个 PR 作为案例**:https://github.com/labuladong/fucking-algorithm/pull/1112 -------------------------------------------------------------------------------- /技术/linux进程.md: -------------------------------------------------------------------------------- 1 | # Linux的进程、线程、文件描述符是什么 2 | 3 |

4 | GitHub 5 | 6 | 7 | 8 |

9 | 10 | ![](https://labuladong.github.io/pictures/souyisou1.png) 11 | 12 | **通知:[数据结构精品课](https://aep.h5.xeknow.com/s/1XJHEO) 和 [递归算法专题课](https://aep.xet.tech/s/3YGcq3) 限时附赠网站会员,全新纸质书[《labuladong 的算法笔记》](https://labuladong.gitee.io/algo/images/book/book_intro_qrcode.jpg) 出版,签名版限时半价!另外,建议你在我的 [网站](https://labuladong.github.io/algo/) 学习文章,体验更好。** 13 | 14 | 15 | 16 | **-----------** 17 | 18 | 说到进程,恐怕面试中最常见的问题就是线程和进程的关系了,那么先说一下答案:**在 Linux 系统中,进程和线程几乎没有区别**。 19 | 20 | Linux 中的进程就是一个数据结构,看明白就可以理解文件描述符、重定向、管道命令的底层工作原理,最后我们从操作系统的角度看看为什么说线程和进程基本没有区别。 21 | 22 | ### 一、进程是什么 23 | 24 | 首先,抽象地来说,我们的计算机就是这个东西: 25 | 26 | ![](https://labuladong.github.io/pictures/linuxProcess/1.jpg) 27 | 28 | 这个大的矩形表示计算机的**内存空间**,其中的小矩形代表**进程**,左下角的圆形表示**磁盘**,右下角的图形表示一些**输入输出设备**,比如鼠标键盘显示器等等。另外,注意到内存空间被划分为了两块,上半部分表示**用户空间**,下半部分表示**内核空间**。 29 | 30 | 用户空间装着用户进程需要使用的资源,比如你在程序代码里开一个数组,这个数组肯定存在用户空间;内核空间存放内核进程需要加载的系统资源,这一些资源一般是不允许用户访问的。但是注意有的用户进程会共享一些内核空间的资源,比如一些动态链接库等等。 31 | 32 | 我们用 C 语言写一个 hello 程序,编译后得到一个可执行文件,在命令行运行就可以打印出一句 hello world,然后程序退出。在操作系统层面,就是新建了一个进程,这个进程将我们编译出来的可执行文件读入内存空间,然后执行,最后退出。 33 | 34 | **你编译好的那个可执行程序只是一个文件**,不是进程,可执行文件必须要载入内存,包装成一个进程才能真正跑起来。进程是要依靠操作系统创建的,每个进程都有它的固有属性,比如进程号(PID)、进程状态、打开的文件等等,进程创建好之后,读入你的程序,你的程序才被系统执行。 35 | 36 | 那么,操作系统是如何创建进程的呢?**对于操作系统,进程就是一个数据结构**,我们直接来看 Linux 的源码: 37 | 38 | ```cpp 39 | struct task_struct { 40 | // 进程状态 41 | long state; 42 | // 虚拟内存结构体 43 | struct mm_struct *mm; 44 | // 进程号 45 | pid_t pid; 46 | // 指向父进程的指针 47 | struct task_struct __rcu *parent; 48 | // 子进程列表 49 | struct list_head children; 50 | // 存放文件系统信息的指针 51 | struct fs_struct *fs; 52 | // 一个数组,包含该进程打开的文件指针 53 | struct files_struct *files; 54 | }; 55 | ``` 56 | 57 | `task_struct` 就是 Linux 内核对于一个进程的描述,也可以称为「进程描述符」。源码比较复杂,我这里就截取了一小部分比较常见的。 58 | 59 | 其中比较有意思的是 `mm` 指针和 `files` 指针。`mm` 指向的是进程的虚拟内存,也就是载入资源和可执行文件的地方;`files` 指针指向一个数组,这个数组里装着所有该进程打开的文件的指针。 60 | 61 | ### 二、文件描述符是什么 62 | 63 | 先说 `files`,它是一个文件指针数组。一般来说,一个进程会从 `files[0]` 读取输入,将输出写入 `files[1]`,将错误信息写入 `files[2]`。 64 | 65 | 举个例子,以我们的角度 C 语言的 `printf` 函数是向命令行打印字符,但是从进程的角度来看,就是向 `files[1]` 写入数据;同理,`scanf` 函数就是进程试图从 `files[0]` 这个文件中读取数据。 66 | 67 | **每个进程被创建时,`files` 的前三位被填入默认值,分别指向标准输入流、标准输出流、标准错误流。我们常说的「文件描述符」就是指这个文件指针数组的索引**,所以程序的文件描述符默认情况下 0 是输入,1 是输出,2 是错误。 68 | 69 | 我们可以重新画一幅图: 70 | 71 | ![](https://labuladong.github.io/pictures/linuxProcess/2.jpg) 72 | 73 | 对于一般的计算机,输入流是键盘,输出流是显示器,错误流也是显示器,所以现在这个进程和内核连了三根线。因为硬件都是由内核管理的,我们的进程需要通过「系统调用」让内核进程访问硬件资源。 74 | 75 | > note:不要忘了,Linux 中一切都被抽象成文件,设备也是文件,可以进行读和写。 76 | 77 | 如果我们写的程序需要其他资源,比如打开一个文件进行读写,这也很简单,进行系统调用,让内核把文件打开,这个文件就会被放到 `files` 的第 4 个位置: 78 | 79 | ![](https://labuladong.github.io/pictures/linuxProcess/3.jpg) 80 | 81 | 明白了这个原理,**输入重定向**就很好理解了,程序想读取数据的时候就会去 `files[0]` 读取,所以我们只要把 `files[0]` 指向一个文件,那么程序就会从这个文件中读取数据,而不是从键盘: 82 | 83 | ```shell 84 | $ command < file.txt 85 | ``` 86 | 87 | ![](https://labuladong.github.io/pictures/linuxProcess/5.jpg) 88 | 89 | 同理,**输出重定向**就是把 `files[1]` 指向一个文件,那么程序的输出就不会写入到显示器,而是写入到这个文件中: 90 | 91 | ```shell 92 | $ command > file.txt 93 | ``` 94 | 95 | ![](https://labuladong.github.io/pictures/linuxProcess/4.jpg) 96 | 97 | 错误重定向也是一样的,就不再赘述。 98 | 99 | **管道符**其实也是异曲同工,把一个进程的输出流和另一个进程的输入流接起一条「管道」,数据就在其中传递,不得不说这种设计思想真的很优美: 100 | 101 | ```shell 102 | $ cmd1 | cmd2 | cmd3 103 | ``` 104 | 105 | ![](https://labuladong.github.io/pictures/linuxProcess/6.jpg) 106 | 107 | 到这里,你可能也看出「Linux 中一切皆文件」设计思路的高明了,不管是设备、另一个进程、socket 套接字还是真正的文件,全部都可以读写,统一装进一个简单的 `files` 数组,进程通过简单的文件描述符访问相应资源,具体细节交于操作系统,有效解耦,优美高效。 108 | 109 | ### 三、线程是什么 110 | 111 | 首先要明确的是,多进程和多线程都是并发,都可以提高处理器的利用效率,所以现在的关键是,多线程和多进程有啥区别。 112 | 113 | 为什么说 Linux 中线程和进程基本没有区别呢,因为从 Linux 内核的角度来看,并没有把线程和进程区别对待。 114 | 115 | 我们知道系统调用 `fork()` 可以新建一个子进程,函数 `pthread()` 可以新建一个线程。**但无论线程还是进程,都是用 `task_struct` 结构表示的,唯一的区别就是共享的数据区域不同**。 116 | 117 | 换句话说,线程看起来跟进程没有区别,只是线程的某些数据区域和其父进程是共享的,而子进程是拷贝副本,而不是共享。就比如说,`mm` 结构和 `files` 结构在线程中都是共享的,我画两张图你就明白了: 118 | 119 | ![](https://labuladong.github.io/pictures/linuxProcess/7.jpg) 120 | 121 | ![](https://labuladong.github.io/pictures/linuxProcess/8.jpg) 122 | 123 | 所以说,我们的多线程程序要利用锁机制,避免多个线程同时往同一区域写入数据,否则可能造成数据错乱。 124 | 125 | 那么你可能问,**既然进程和线程差不多,而且多进程数据不共享,即不存在数据错乱的问题,为什么多线程的使用比多进程普遍得多呢**? 126 | 127 | 因为现实中数据共享的并发更普遍呀,比如十个人同时从一个账户取十元,我们希望的是这个共享账户的余额正确减少一百元,而不是希望每人获得一个账户的拷贝,每个拷贝账户减少十元。 128 | 129 | 当然,必须要说明的是,只有 Linux 系统将线程看做共享数据的进程,不对其做特殊看待,其他的很多操作系统是对线程和进程区别对待的,线程有其特有的数据结构,我个人认为不如 Linux 的这种设计简洁,增加了系统的复杂度。 130 | 131 | 在 Linux 中新建线程和进程的效率都是很高的,对于新建进程时内存区域拷贝的问题,Linux 采用了 copy-on-write 的策略优化,也就是并不真正复制父进程的内存空间,而是等到需要写操作时才去复制。**所以 Linux 中新建进程和新建线程都是很迅速的**。 132 | 133 | 134 | 135 |
136 |
137 | 引用本文的文章 138 | 139 | - [Linux 管道和重定向的坑](https://labuladong.github.io/article/fname.html?fname=linux技巧3) 140 | - [关于 Linux shell 你必须知道的](https://labuladong.github.io/article/fname.html?fname=linuxshell) 141 | 142 |

143 | 144 | 145 | 146 | 147 | 148 | **_____________** 149 | 150 | **《labuladong 的算法小抄》已经出版,关注公众号查看详情;后台回复「**全家桶**」可下载配套 PDF 和刷题全家桶**: 151 | 152 | ![](https://labuladong.github.io/pictures/souyisou2.png) 153 | 154 | ======其他语言代码====== -------------------------------------------------------------------------------- /技术/redis入侵.md: -------------------------------------------------------------------------------- 1 | # Redis 入侵 2 | 3 |

4 | GitHub 5 | 6 | 7 | 8 |

9 | 10 | ![](https://labuladong.github.io/pictures/souyisou1.png) 11 | 12 | **通知:[数据结构精品课](https://aep.h5.xeknow.com/s/1XJHEO) 和 [递归算法专题课](https://aep.xet.tech/s/3YGcq3) 限时附赠网站会员,全新纸质书[《labuladong 的算法笔记》](https://labuladong.gitee.io/algo/images/book/book_intro_qrcode.jpg) 出版,签名版限时半价!另外,建议你在我的 [网站](https://labuladong.github.io/algo/) 学习文章,体验更好。** 13 | 14 | 15 | 16 | **-----------** 17 | 18 | 好吧,我也做了回标题党,像我这么细心的同学,怎么可能让服务器被入侵呢? 19 | 20 | 其实是这样的,昨天我和一个朋友聊天,他说他自己有一台云服务器运行了 Redis 数据库,有一天突然发现数据库里的**数据全没了**,只剩下一个奇奇怪怪的键值对,其中值看起来像一个 RSA 公钥的字符串,他以为是误操作删库了,幸好自己的服务器里没啥重要的数据,也就没在意。 21 | 22 | 经过一番攀谈交心了解到,他跑了一个比较古老已经停止维护的开源项目,安装的旧版本的 Redis,而且他对 Linux 的使用不是很熟练。我就知道,他的服务器已经被攻陷了,想到也许还会有不少像我这位朋友的人,不重视操作系统的权限、防火墙的设置和数据库的保护,我就写一篇文章简单看看这种情况出现的原因,以及如何防范。 23 | 24 | > note:这种手法现在已经行不通了,因为新版本 Redis 都增加了 protect mode,增加了安全性,我们只能在本地简单模拟一下,就别乱试了。 25 | 26 | ### 事件经过 27 | 28 | 其实这种攻击手法都是 2015 年的事了,那时候 Redis 的安全保护机制比较差,只能靠运维人员来合理配置以保证数据库的安全。有段时间,全球几万个 Redis 节点遭到了攻击,出现了上述奇怪的现象,所有数据被清空,只剩一个键叫 `crackit`,它的值形似 RSA 公钥的字符串。 29 | 30 | 后来查证,攻击者利用 Redis 动态设置配置和数据持久化的功能,把自己的 RSA 公钥写入到了被攻击服务器的 `/root/.ssh/authored_keys` 这个文件,从而可以用私钥直接登录对方的 root 用户,侵入对方系统。 31 | 32 | 沦陷的服务器安全防护做的很不好,具体如下: 33 | 34 | 1、Redis 的端口是默认端口,而且可以从公网访问。 35 | 36 | 2、Redis 还没设密码。 37 | 38 | 3、Redis 进程是由 root 用户启动的。 39 | 40 | 以上每个点都是比较危险的,合在一起,那真是很致命了。且不说别人把公钥写到你的系统里,就说连上你的数据库然后删库,那损失都够大了。那么具体的流程是什么呢,下面我在本地回环地址上简单演示一下。 41 | 42 | ### 本地演示 43 | 44 | Redis 监听的默认端口是 6379,我们设置它接收网卡 127.0.0.1 的连接,这样我从本地肯定可以连接 Redis,以此模拟「从公网可以访问 Redis」这一条件。 45 | 46 | 现在我是名叫 fdl 的普通用户,我想用 ssh 登录我系统上的 root 用户,要输入 root 的密码,我不知道,所以没办法登录。 47 | 48 | 除了密码登录之外,还可以使用 RSA 密钥对登录,但是必须要把我的公钥存到 root 的家目录中 `/root/.ssh/authored_keys`。我们知道 `/root` 目录的权限设置是不允许任何其他用户闯入读写的: 49 | 50 | ![](https://labuladong.github.io/pictures/redis入侵/1.png) 51 | 52 | 但是,我发现自己竟然可以直接访问 Redis: 53 | 54 | ![](https://labuladong.github.io/pictures/redis入侵/2.png) 55 | 56 | 如果 Redis 是以 root 的身份运行的,那么我就可以通过操作 Redis,让它把我的公钥写到 root 的家目录中。Redis 有一种持久化方式是生成 RDB 文件,其中会包含原始数据。 57 | 58 | 我露出了邪恶的微笑,先把 Redis 中的数据全部清空,然后把我的 RSA 公钥写到数据库里,这里在开头和结尾加换行符目的是避免 RDB 文件生成过程中损坏到公钥字符串: 59 | 60 | ![](https://labuladong.github.io/pictures/redis入侵/3.png) 61 | 62 | 命令 Redis 把生成的数据文件保存到 `/root/.ssh/` 中的 `authored_keys` 文件中: 63 | 64 | ![](https://labuladong.github.io/pictures/redis入侵/4.png) 65 | 66 | 现在,root 的家目录中已经包含了我们的 RSA 公钥,我们现在可以通过密钥对登录进 root 了: 67 | 68 | ![](https://labuladong.github.io/pictures/redis入侵/5.png) 69 | 70 | 看一下刚才写入 root 家的公钥: 71 | 72 | ![](https://labuladong.github.io/pictures/redis入侵/6.png) 73 | 74 | 乱码是 GDB 文件的某种编码吧,但是中间的公钥被完整保存了,而且 ssh 登录程序竟然也识别了这段被乱码包围的公钥! 75 | 76 | 至此,拥有了 root 权限,就可以为所欲为了。。。 77 | 78 | ### 吸取教训 79 | 80 | 虽然现在基本不会受到这种攻击(新版本的 Redis 没有密码时默认不对外网开放),但是对于系统的安全性是每个人都应该重视的。 81 | 82 | 我们自己折腾东西,用个低配云服务器,为了省事儿一般也不认真配置防火墙,数据库不设密码或者设成 admin、root 这样简单的密码,反正也没啥数据。这样肯定不是个好习惯。 83 | 84 | 现在我们的计算机系统越来越完善,每个成熟的项目都由最优秀的一帮人维护,从技术上说应该算是无懈可击了,那么唯一可能出问题的地方就在于使用它们的人。 85 | 86 | 就像经常看到有人的 QQ 被盗,我相信盗号的人肯定不是跑到腾讯的数据库里盗号,肯定是 QQ 号主安全防范意识差,在哪个钓鱼网站输入了自己的账号密码,导致被盗。我基本没见过微信被盗的,可能是微信弱化密码登录,改用二维码扫描登录的原因。这应该也算是一种安全方面的考量吧,毕竟微信是有支付功能的。 87 | 88 | 上面这种骗局对于技术人来说,看看 url,浏览器分析一下网络包就很容易识别出来,但是你还别不信,一般人真的搞不明白怎么识别钓鱼网站和官方网站。就像我真没想到都 2020 年了,还有人在找 Redis 的这个漏洞,而且还有人中招。。。 89 | 90 | 那么说回 Redis 数据库的使用,在官网上明确写出了安全防护的建议,我简单总结一下吧: 91 | 92 | 1、不要用 root 用户启动 Redis Server,而且一定要设置密码,而且密码不要太短,否则容易被暴力破解。 93 | 94 | 2、配置服务器防火墙和 Redis 的 config 文件,尽量不要让 Redis 与外界接触。 95 | 96 | 3、利用 rename 功能伪装 flushall 这种危险命令,以防被删库,丢失数据。 97 | 98 | 99 | 100 | 101 | 102 | **_____________** 103 | 104 | **《labuladong 的算法小抄》已经出版,关注公众号查看详情;后台回复「**全家桶**」可下载配套 PDF 和刷题全家桶**: 105 | 106 | ![](https://labuladong.github.io/pictures/souyisou2.png) 107 | 108 | ======其他语言代码====== -------------------------------------------------------------------------------- /技术/session和cookie.md: -------------------------------------------------------------------------------- 1 | # 一文读懂 session 和 cookie 2 | 3 |

4 | GitHub 5 | 6 | 7 | 8 |

9 | 10 | ![](https://labuladong.github.io/pictures/souyisou1.png) 11 | 12 | **通知:[数据结构精品课](https://aep.h5.xeknow.com/s/1XJHEO) 和 [递归算法专题课](https://aep.xet.tech/s/3YGcq3) 限时附赠网站会员,全新纸质书[《labuladong 的算法笔记》](https://labuladong.gitee.io/algo/images/book/book_intro_qrcode.jpg) 出版,签名版限时半价!另外,建议你在我的 [网站](https://labuladong.github.io/algo/) 学习文章,体验更好。** 13 | 14 | 15 | 16 | **-----------** 17 | 18 | cookie 大家应该都熟悉,比如说登录某些网站一段时间后,就要求你重新登录;再比如有的同学很喜欢玩爬虫技术,有时候网站就是可以拦截住你的爬虫,这些都和 cookie 有关。如果你明白了服务器后端对于 cookie 和 session 的处理逻辑,就可以解释这些现象,甚至钻一些空子无限白嫖,待我慢慢道来。 19 | 20 | ### 一、session 和 cookie 简介 21 | 22 | cookie 的出现是因为 HTTP 是无状态的一种协议,换句话说,服务器记不住你,可能你每刷新一次网页,就要重新输入一次账号密码进行登录。这显然是让人无法接受的,cookie 的作用就好比服务器给你贴个标签,然后你每次向服务器再发请求时,服务器就能够 cookie 认出你。 23 | 24 | 抽象地概括一下:**一个 cookie 可以认为是一个「变量」,形如 `name=value`,存储在浏览器;一个 session 可以理解为一种数据结构,多数情况是「映射」(键值对),存储在服务器上**。 25 | 26 | 注意,我说的是「一个」cookie 可以认为是一个变量,但是服务器可以一次设置多个 cookie,所以有时候说 cookie 是「一组」键值对儿,这也可以说得通。 27 | 28 | cookie 可以在服务器端通过 HTTP 的 SetCookie 字段设置 cookie,比如我用 Go 语言写的一个简单服务: 29 | 30 | ```go 31 | func cookie(w http.ResponseWriter, r *http.Request) { 32 | // 设置了两个 cookie 33 | http.SetCookie(w, &http.Cookie{ 34 | Name: "name1", 35 | Value: "value1", 36 | }) 37 | 38 | http.SetCookie(w, &http.Cookie{ 39 | Name: "name2", 40 | Value: "value2", 41 | }) 42 | // 将字符串写入网页 43 | fmt.Fprintln(w, "页面内容") 44 | } 45 | ``` 46 | 47 | 当浏览器访问对应网址时,通过浏览器的开发者工具查看此次 HTTP 通信的细节,可以看见服务器的回应发出了两次 `SetCookie` 命令: 48 | 49 | ![](https://labuladong.github.io/pictures/session/1.png) 50 | 51 | 在这之后,浏览器的请求中的 `Cookie` 字段就带上了这两个 cookie: 52 | 53 | ![](https://labuladong.github.io/pictures/session/2.png) 54 | 55 | **cookie 的作用其实就是这么简单,无非就是服务器给每个客户端(浏览器)打的标签**,方便服务器辨认而已。当然,HTTP 还有很多参数可以设置 cookie,比如过期时间,或者让某个 cookie 只有某个特定路径才能使用等等。 56 | 57 | 但问题是,我们也知道现在的很多网站功能很复杂,而且涉及很多的数据交互,比如说电商网站的购物车功能,信息量大,而且结构也比较复杂,无法通过简单的 cookie 机制传递这么多信息,而且要知道 cookie 字段是存储在 HTTP header 中的,就算能够承载这些信息,也会消耗很多的带宽,比较消耗网络资源。 58 | 59 | session 就可以配合 cookie 解决这一问题,比如说一个 cookie 存储这样一个变量 `sessionID=xxxx`,仅仅把这一个 cookie 传给服务器,然后服务器通过这个 ID 找到对应的 session,这个 session 是一个数据结构,里面存储着该用户的购物车等详细信息,服务器可以通过这些信息返回该用户的定制化网页,有效解决了追踪用户的问题。 60 | 61 | **session 是一个数据结构,由网站的开发者设计,所以可以承载各种数据**,只要客户端的 cookie 传来一个唯一的 session ID,服务器就可以找到对应的 session,认出这个客户。 62 | 63 | 当然,由于 session 存储在服务器中,肯定会消耗服务器的资源,所以 session 一般都会有一个过期时间,服务器一般会定期检查并删除过期的 session,如果后来该用户再次访问服务器,可能就会面临重新登录等等措施,然后服务器新建一个 session,将 session ID 通过 cookie 的形式传送给客户端。 64 | 65 | 那么,我们知道 cookie 和 session 的原理,有什么切实的好处呢?**除了应对面试,我给你说一个鸡贼的用处,就是可以白嫖某些服务**。 66 | 67 | 有些网站,你第一次使用它的服务,它直接免费让你试用,但是用一次之后,就让你登录然后付费继续使用该服务。而且你发现网站似乎通过某些手段记住了你的电脑,除非你换个电脑或者换个浏览器才能再白嫖一次。 68 | 69 | 那么问题来了,你试用的时候没有登录,网站服务器是怎么记住你的呢?这就很显然了,服务器一定是给你的浏览器打了 cookie,后台建立了对应的 session 记录你的状态。你的浏览器在每次访问该网站的时候都会听话地带着 cookie,服务器一查 session 就知道这个浏览器已经免费使用过了,得让它登录付费,不能让它继续白嫖了。 70 | 71 | 那如果我不让浏览器发送 cookie,每次都伪装成一个第一次来试用的小萌新,不就可以不断白嫖了么?浏览器会把网站的 cookie 以文件的形式存在某些地方(不同的浏览器配置不同),你把他们找到然后删除就行了。但是对于 Firefox 和 Chrome 浏览器,有很多插件可以直接编辑 cookie,比如我的 Chrome 浏览器就用的一款叫做 EditThisCookie 的插件,这是他们官网: 72 | 73 | ![](https://labuladong.github.io/pictures/session/3.png) 74 | 75 | 这类插件可以读取浏览器在当前网页的 cookie,点开插件可以任意编辑和删除 cookie。**当然,偶尔白嫖一两次还行,不鼓励高频率白嫖,想常用还是掏钱吧,否则网站赚不到钱,就只能取消免费试用这个机制了**。 76 | 77 | 以上就是关于 cookie 和 session 的简单介绍,cookie 是 HTTP 协议的一部分,不算复杂,而 session 是可以定制的,所以下面详细看一下实现 session 管理的代码架构吧。 78 | 79 | ### 二、session 的实现 80 | 81 | session 的原理不难,但是具体实现它可是很有技巧的,一般需要三个组件配合完成,它们分别是 `Manager`、`Provider` 和 `Session` 三个类(接口)。 82 | 83 | ![](https://labuladong.github.io/pictures/session/4.jpg) 84 | 85 | 1、浏览器通过 HTTP 协议向服务器请求路径 `/content` 的网页资源,对应路径上有一个 Handler 函数接收请求,解析 HTTP header 中的 cookie,得到其中存储的 sessionID,然后把这个 ID 发给 `Manager`。 86 | 87 | 2、`Manager` 充当一个 session 管理器的角色,主要存储一些配置信息,比如 session 的存活时间,cookie 的名字等等。而所有的 session 存在 `Manager` 内部的一个 `Provider` 中。所以 `Manager` 会把 `sid`(sessionID)传递给 `Provider`,让它去找这个 ID 对应的具体是哪个 session。 88 | 89 | 3、`Provider` 就是一个容器,最常见的应该就是一个散列表,将每个 `sid` 和对应的 session 一一映射起来。收到 `Manager` 传递的 `sid` 之后,它就找到 `sid` 对应的 session 结构,也就是 `Session` 结构,然后返回它。 90 | 91 | 4、`Session` 中存储着用户的具体信息,由 Handler 函数中的逻辑拿出这些信息,生成该用户的 HTML 网页,返回给客户端。 92 | 93 | 那么你也许会问,为什么搞这么麻烦,直接在 Handler 函数中搞一个哈希表,然后存储 `sid` 和 `Session` 结构的映射不就完事儿了? 94 | 95 | **这就是设计层面的技巧了**,下面就来说说,为什么分成 `Manager`、`Provider` 和 `Session`。 96 | 97 | 先从最底层的 `Session` 说。既然 session 就是键值对,为啥不直接用哈希表,而是要抽象出这么一个数据结构呢? 98 | 99 | 第一,因为 `Session` 结构可能不止存储了一个哈希表,还可以存储一些辅助数据,比如 `sid`,访问次数,过期时间或者最后一次的访问时间,这样便于实现想 LRU、LFU 这样的算法。 100 | 101 | 第二,因为 session 可以有不同的存储方式。如果用编程语言内置的哈希表,那么 session 数据就是存储在内存中,如果数据量大,很容易造成程序崩溃,而且一旦程序结束,所有 session 数据都会丢失。所以可以有很多种 session 的存储方式,比如存入缓存数据库 Redis,或者存入 MySQL 等等。 102 | 103 | 因此,`Session` 结构提供一层抽象,屏蔽不同存储方式的差异,只要提供一组通用接口操纵键值对: 104 | 105 | ```go 106 | type Session interface { 107 | // 设置键值对 108 | Set(key, val interface{}) 109 | // 获取 key 对应的值 110 | Get(key interface{}) interface{} 111 | // 删除键 key 112 | Delete(key interface{}) 113 | } 114 | ``` 115 | 116 | 再说 `Provider` 为啥要抽象出来。我们上面那个图的 `Provider` 就是一个散列表,保存 `sid` 到 `Session` 的映射,但是实际中肯定会更加复杂。我们不是要时不时删除一些 session 吗,除了设置存活时间之外,还可以采用一些其他策略,比如 LRU 缓存淘汰算法,这样就需要 `Provider` 内部使用哈希链表这种数据结构来存储 session。 117 | 118 | > tip:关于 LRU 算法的奥妙,参见前文 [LRU 算法详解](https://labuladong.github.io/article/fname.html?fname=LRU算法)。 119 | 120 | 因此,`Provider` 作为一个容器,就是要屏蔽算法细节,以合理的数据结构和算法组织 `sid` 和 `Session` 的映射关系,只需要实现下面这几个方法实现对 session 的增删查改: 121 | 122 | ```go 123 | type Provider interface { 124 | // 新增并返回一个 session 125 | SessionCreate(sid string) (Session, error) 126 | // 删除一个 session 127 | SessionDestroy(sid string) 128 | // 查找一个 session 129 | SessionRead(sid string) (Session, error) 130 | // 修改一个session 131 | SessionUpdate(sid string) 132 | // 通过类似 LRU 的算法回收过期的 session 133 | SessionGC(maxLifeTime int64) 134 | } 135 | ``` 136 | 137 | 最后说 `Manager`,大部分具体工作都委托给 `Session` 和 `Provider` 承担了,`Manager` 主要就是一个参数集合,比如 session 的存活时间,清理过期 session 的策略,以及 session 的可用存储方式。`Manager` 屏蔽了操作的具体细节,我们可以通过 `Manager` 灵活地配置 session 机制。 138 | 139 | 综上,session 机制分成几部分的最主要原因就是解耦,实现定制化。我在 Github 上看过几个 Go 语言实现的 session 服务,源码都很简单,有兴趣的朋友可以学习学习: 140 | 141 | https://github.com/alexedwards/scs 142 | 143 | https://github.com/astaxie/build-web-application-with-golang 144 | 145 | 146 | 147 | 148 | 149 | **_____________** 150 | 151 | **《labuladong 的算法小抄》已经出版,关注公众号查看详情;后台回复「**全家桶**」可下载配套 PDF 和刷题全家桶**: 152 | 153 | ![](https://labuladong.github.io/pictures/souyisou2.png) 154 | 155 | ======其他语言代码====== -------------------------------------------------------------------------------- /技术/刷题技巧.md: -------------------------------------------------------------------------------- 1 | # 算法笔试骗分套路 2 | 3 |

4 | GitHub 5 | 6 | 7 | 8 |

9 | 10 | ![](https://labuladong.github.io/pictures/souyisou1.png) 11 | 12 | **通知:[数据结构精品课](https://aep.h5.xeknow.com/s/1XJHEO) 和 [递归算法专题课](https://aep.xet.tech/s/3YGcq3) 限时附赠网站会员,全新纸质书[《labuladong 的算法笔记》](https://labuladong.gitee.io/algo/images/book/book_intro_qrcode.jpg) 出版,签名版限时半价!另外,建议你在我的 [网站](https://labuladong.github.io/algo/) 学习文章,体验更好。** 13 | 14 | 15 | 16 | **-----------** 17 | 18 | 首先回答一个问题,刷力扣题是直接在网页上刷比较好还是在本地 IDE 上刷比较好? 19 | 20 | 如果是牛客网笔试那种自己处理输入输出的判题形式,一定要在 IDE 上写,这个没啥说的,但**像力扣这种判题形式,我个人偏好直接在网页上刷**,原因有二: 21 | 22 | **1、方便** 23 | 24 | 因为力扣有的数据结构是自定的,比如说 `TreeNode`,`ListNode` 这种,在本地你还得把这个类 copy 过去。 25 | 26 | 而且在 IDE 上没办法测试,写完代码之后还得粘贴到网页上跑测试数据,那还不如直接网页上写呢。 27 | 28 | 算法又不是工程代码,量都比较小,IDE 的自动补全带来的收益基本可以忽略不计。 29 | 30 | **2、实用** 31 | 32 | 到时候面试的时候,面试官给你出的算法题大都是希望你直接在网页上完成的,最好是边写边讲你的思路。 33 | 34 | 如果平时练习的时候就习惯没有 IDE 的自动补全,习惯手写代码大脑编译,到时候面试的时候写代码就能更快更从容。 35 | 36 | 之前我面快手的时候,有个面试官让我 [实现 LRU 算法](https://labuladong.github.io/article/fname.html?fname=LRU算法),我直接把双链表的实现、哈希链表的实现,在网页上全写出来了,而且一次无 bug 跑通,可以看到面试官惊讶的表情😂 37 | 38 | 我秋招能当 offer 收割机,很大程度上就是因为手写算法这一关超出面试官的预期,其实都是因为之前在网页上刷题练出来的。 39 | 40 | 当然,实在不想在网页上刷,也可以用我的 vscode 刷题插件或者 JetBrains 刷题插件,插件和我的网站内容都有完美的融合: 41 | 42 | ![](https://labuladong.github.io/pictures/others/全家桶.jpg) 43 | 44 | 接下来介绍几个很实用的「投机取巧」的办法和调试技巧,全方位提高你通过笔试的概率。 45 | 46 | 47 | 48 |
49 |
50 | 引用本文的文章 51 | 52 | - [带权重的随机选择算法](https://labuladong.github.io/article/fname.html?fname=随机权重) 53 | 54 |

55 | 56 | 57 | 58 | 59 | 60 | **_____________** 61 | 62 | 本文为会员内容,请扫码关注公众号或 [点这里](https://appktavsiei5995.pc.xiaoe-tech.com/detail/i_64a923dde4b007b201a392d0/1) 查看: 63 | 64 | ![](https://labuladong.github.io/pictures/qrcode.jpg) -------------------------------------------------------------------------------- /技术/在线练习平台.md: -------------------------------------------------------------------------------- 1 | # 在线刷题学习平台 2 | 3 |

4 | GitHub 5 | 6 | 7 | 8 |

9 | 10 | ![](https://labuladong.github.io/pictures/souyisou1.png) 11 | 12 | **通知:[数据结构精品课](https://aep.h5.xeknow.com/s/1XJHEO) 和 [递归算法专题课](https://aep.xet.tech/s/3YGcq3) 限时附赠网站会员,全新纸质书[《labuladong 的算法笔记》](https://labuladong.gitee.io/algo/images/book/book_intro_qrcode.jpg) 出版,签名版限时半价!另外,建议你在我的 [网站](https://labuladong.github.io/algo/) 学习文章,体验更好。** 13 | 14 | 15 | 16 | **-----------** 17 | 18 | 虽说我没事就喜欢喷应试教育,但我也从应试教育中发现了一个窍门:如果能够以刷题的形式学习某项技能,效率和效果是最佳的。对于技术的学习,我经常面临的困境是,**理论知识知道的不少,但是有的场景实在无法模拟,缺少亲自动手实践的机会**,如果能有一本带标准答案的习题册让我刷刷就好了。 19 | 20 | 所以在学习新技术时,我首先会去搜索是否有在线刷题平台,你还别说,有的大神真就做了很不错的在线练习平台,下面就介绍几个平台,分别是学习 Git、SQL、正则表达式的在线练习平台。 21 | 22 | ### 一、练习 Git 23 | 24 | 这是个叫做 Learning Git Branching 的项目,是我一定要推荐的: 25 | 26 | ![](https://labuladong.github.io/pictures/online/1.png) 27 | 28 | 正如对话框中的自我介绍,这确实也是我至今发现的**最好**的 Git 动画教程,没有之一。 29 | 30 | 想当年我用 Git 就会 `add .`,`clone`,`push`,`pull`,`commit` 几个命令,其他的命令完全不会,Git 就是一个下载器,Github 就是个资源网站加免费图床,命令能不能达成目的都是靠运气。什么版本控制,我根本搞不懂,也懒得去看那一堆乱七八糟的文档。 31 | 32 | 这个网站的教程不是给你举那种修改文件的细节例子,而是将每次 `commit` 都抽象成树的节点,**用动画闯关的形式**,让你自由使用 Git 命令完成目标: 33 | 34 | ![](https://labuladong.github.io/pictures/online/2.png) 35 | 36 | 所有 Git 分支都被可视化了,你只要在左侧的命令行输入 Git 命令,分支会进行相应的变化,只要达成任务目标,你就过关啦!网站还会记录你的命令数,试试能不能以最少的命令数过关! 37 | 38 | ![](https://labuladong.github.io/pictures/online/3.png) 39 | 40 | 我一开始以为这个教程只包含本地 Git 仓库的版本管理,**后来我惊奇地发现它还有远程仓库的操作教程**! 41 | 42 | ![](https://labuladong.github.io/pictures/online/4.png) 43 | 44 | ![](https://labuladong.github.io/pictures/online/5.png) 45 | 46 | 真的跟玩游戏一样,难度设计合理,流畅度很好,我一玩都停不下来了,几小时就打通了,哈哈哈! 47 | 48 | ![](https://labuladong.github.io/pictures/online/6.png) 49 | 50 | 总之,这个教程很适合初学和进阶,如果你觉得自己对 Git 的掌握还不太好,用 Git 命令还是靠碰运气,就可以玩玩这个教程,相信能够让你更熟练地使用 Git。 51 | 52 | 它是一个开源项目,Github 项目地址: 53 | 54 | https://github.com/pcottle/learnGitBranching 55 | 56 | 教程网站地址: 57 | 58 | https://learngitbranching.js.org 59 | 60 | ### 二、练习正则表达式 61 | 62 | **正则表达式是个非常强有力的工具**,可以说计算机中的一切数据都是字符,借助正则表达式这种模式匹配工具,操作计算机可以说是如虎添翼。 63 | 64 | 我这里要推荐两个网站,一个是练习平台,一个是测试正则表达式的平台。 65 | 66 | 先说练习平台,叫做 RegexOne: 67 | 68 | ![](https://labuladong.github.io/pictures/online/9.png) 69 | 70 | 前面有基本教程,后面有一些常见的正则表达式题目,比如判断邮箱、URL、电话号,或者抽取日志的关键信息等等。 71 | 72 | 只要写出符合要求的正则表达式,就可以进入下一个问题,关键是每道题还有标准答案,可以点击下面的 solution 按钮查看: 73 | 74 | ![](https://labuladong.github.io/pictures/online/10.png) 75 | 76 | RegexOne 网址: 77 | 78 | https://regexone.com/ 79 | 80 | 再说测试工具,是个叫做 RegExr 的 Github 项目,这是它的网站: 81 | 82 | ![](https://labuladong.github.io/pictures/online/11.png) 83 | 84 | 可以看见,输入文本和正则模式串后,**网站会给正则表达式添加好看且容易辨认的样式,自动在文本中搜索模式串,高亮显示匹配的字符串,并且还会显示每个分组捕获的字符串**。 85 | 86 | 这个网站可以配合前面的正则练习平台使用,在这里尝试各种表达式,成功匹配之后粘贴过去。 87 | 88 | RegExr 网址: 89 | 90 | https://regexr.com/ 91 | 92 | ### 三、练习 SQL 93 | 94 | 这是一个叫做 SQLZOO 的网站,左侧是所有的练习内容: 95 | 96 | ![](https://labuladong.github.io/pictures/online/7.png) 97 | 98 | SQLZOO 是一款很好用的 SQL 练习平台,英文不难理解,可以直接看英文版,但是也可以切换繁体中文,比较友好。 99 | 100 | 这里都是比较常用的 SQL 命令,给你一个需求,你写 SQL 语句实现正确的查询结果。**最重要的是,这里不仅对每个命令的用法有详细解释,每个专题后面还有选择题(quiz),而且有判题系统,甚至有的比较难的题目还有视频讲解**: 101 | 102 | ![](https://labuladong.github.io/pictures/online/8.png) 103 | 104 | 至于难度,循序渐进,即便对新手也很友好,靠后的问题确实比较有技巧性,相信这是热爱思维挑战的人喜欢的!LeetCode 也有 SQL 相关的题目,不过难度一般比较大,我觉得 SQLZOO 刷完基础 SQL 命令再去 LeetCode 刷比较合适。 105 | 106 | 网站地址: 107 | 108 | https://sqlzoo.net/ 109 | 110 | 111 | 112 |
113 |
114 | 引用本文的文章 115 | 116 | - [我用四个命令概括了 Git 的所有套路](https://labuladong.github.io/article/fname.html?fname=git常用命令) 117 | 118 |

119 | 120 | 121 | 122 | 123 | 124 | **_____________** 125 | 126 | **《labuladong 的算法小抄》已经出版,关注公众号查看详情;后台回复「**全家桶**」可下载配套 PDF 和刷题全家桶**: 127 | 128 | ![](https://labuladong.github.io/pictures/souyisou2.png) 129 | 130 | ======其他语言代码====== -------------------------------------------------------------------------------- /技术/密码技术.md: -------------------------------------------------------------------------------- 1 | # 密码算法的前世今生 2 | 3 |

4 | GitHub 5 | 6 | 7 | 8 |

9 | 10 | ![](https://labuladong.github.io/pictures/souyisou1.png) 11 | 12 | **通知:[数据结构精品课](https://aep.h5.xeknow.com/s/1XJHEO) 和 [递归算法专题课](https://aep.xet.tech/s/3YGcq3) 限时附赠网站会员,全新纸质书[《labuladong 的算法笔记》](https://labuladong.gitee.io/algo/images/book/book_intro_qrcode.jpg) 出版,签名版限时半价!另外,建议你在我的 [网站](https://labuladong.github.io/algo/) 学习文章,体验更好。** 13 | 14 | 15 | 16 | **-----------** 17 | 18 | 说到密码,我们第一个想到的就是登陆账户的密码,但是从密码学的角度来看,这种根本就不算合格的密码。 19 | 20 | 为什么呢,因为我们的账户密码,是依靠隐蔽性来达到加密作用:密码藏在我心里,你不知道,所以你登不上我的账户。 21 | 22 | 然而密码技术认为,「保密」信息总有一天会被扒出来,所以加密算法不应该依靠「保密」来保证机密性,而应该做到:即便知道了加密算法,依然无计可施。说的魔幻一点就是,告诉你我的密码,你依然不知道我的密码。 23 | 24 | 最玄学的就是 Diffie-Hellman 密钥交换算法,我当初就觉得很惊奇,两个人当着你的面互相报几个数字,他们就可以拥有一个共同的秘密,而你却根本不可能算出来这个秘密。下文会着重介绍一下这个算法。 25 | 26 | 本文讨论的密码技术要解决的主要是信息传输中的加密和解密问题。要假设数据传输过程是不安全的,所有信息都在被窃听的,所以发送端要把信息加密,接收方收到信息之后,肯定得知道如何解密。有意思的是,如果你能够让接收者知道如何解密,那么窃听者不是也能够知道如何解密了吗? 27 | 28 | 下面,**我们会介绍对称加密算法、密钥交换算法、非对称加密算法、数字签名、公钥证书**,看看解决安全传输问题的一路坎坷波折。 29 | 30 | ### 一、对称性加密 31 | 32 | 对称性密码,也叫共享密钥密码,顾名思义,这种加密方式用相同的密钥进行加密和解密。 33 | 34 | 比如我说一种最简单的对称加密的方法。首先我们知道信息都可以表示成 0/1 比特序列,也知道相同的两个比特序列做异或运算的结果为 0。 35 | 36 | 那么我们就可以生成一个长度和原始信息一样的随机比特序列作为密钥,然后用它对原始信息做异或运算,就生成了密文。反之,再用该密钥对密文做一次异或运算,就可以恢复原始信息。 37 | 38 | 这是一个简单例子,不过有些过于简单,有很多问题。比如密钥的长度和原始信息完全一致,如果原始信息很大,密钥也会一样大,而且生成大量真随机比特序列的计算开销也比较大。 39 | 40 | 当然,有很多更复杂优秀的对称加密算法解决了这些问题,比如 Rijndael 算法、三重 DES 算法等等。**它们从算法上是无懈可击的,也就是拥有巨大的密钥空间,基本无法暴力破解,而且加密过程相对快速**。 41 | 42 | **但是,一切对称加密算法的软肋在于密钥的配送**。加密和解密用同一个密钥,发送方必须设法把密钥发送给接收方。如果窃听者有能力窃取密文,肯定也可以窃取密钥,那么再无懈可击的算法依然不攻自破。 43 | 44 | 所以,下面介绍两种解决密钥配送问题最常见的算法,分别是 Diffie-Hellman 密钥交换算法和非对称加密算法。 45 | 46 | ### 二、密钥交换算法 47 | 48 | 我们所说的密钥一般就是一个很大的数字,算法用这个数加密、解密。问题在于,信道是不安全的,所有发出的数据都会被窃取。换句话说,有没有一种办法,能够让两个人在众目睽睽之下,光明正大地交换一个秘密,把对称性密钥安全地送到接收方的手中? 49 | 50 | Diffie-Hellman 密钥交换算法可以做到。**准确的说,该算法并不是把一个秘密安全地「送给」对方,而是通过一些共享的数字,双方「心中」各自「生成」了一个相同的秘密,而且双方的这个秘密,是第三方窃听者无法生成的**。 51 | 52 | 也许这就是传说中的心有灵犀一点通吧。 53 | 54 | 这个算法规则不算复杂,你甚至都可以找个朋友尝试一下共享秘密,等会我会简单画出它的基本流程。在此之前,需要明确一个问题:**并不是所有运算都有逆运算**。 55 | 56 | 最简单的例子就是我们熟知的单向散列函数,给一个数字 `a` 和一个散列函数 `f`,你可以很快计算出 `f(a)`,但是如果给你 `f(a)` 和 `f`,推出 `a` 是一件基本做不到的事。密钥交换算法之所以看起来如此玄幻,就是利用了这种不可逆的性质。 57 | 58 | 下面,看下密钥交换算法的流程是什么,按照命名惯例,准备执行密钥交换算法的双方称为 Alice 和 Bob,在网络中企图窃取他俩通信内容的坏人称为 Hack 吧。 59 | 60 | 首先,Alice 和 Bob 协商出两个数字 `N` 和 `G` 作为生成元,当然协商过程可以被窃听者 Hack 窃取,所以我把这两个数画到中间,代表三方都知道: 61 | 62 | ![](https://labuladong.github.io/pictures/密码技术/1.jpg) 63 | 64 | 现在 Alice 和 Bob **心中**各自想一个数字出来,分别称为 `A` 和 `B` 吧: 65 | 66 | ![](https://labuladong.github.io/pictures/密码技术/2.jpg) 67 | 68 | 现在 Alice 将自己心里的这个数字 `A` 和 `G` 通过某些运算得出一个数 `AG`,然后发给 Bob;Bob 将自己心里的数 `B` 和 `G` 通过相同的运算得出一个数 `BG`,然后发给 Alice: 69 | 70 | ![](https://labuladong.github.io/pictures/密码技术/3.jpg) 71 | 72 | 现在的情况变成这样了: 73 | 74 | ![](https://labuladong.github.io/pictures/密码技术/4.jpg) 75 | 76 | 注意,类似刚才举的散列函数的例子,知道 `AG` 和 `G`,并不能反推出 `A` 是多少,`BG` 同理。 77 | 78 | 那么,Alice 可以通过 `BG` 和自己的 `A` 通过某些运算得到一个数 `ABG`,Bob 也可以通过 `AG` 和自己的 `B` 通过某些运算得到 `ABG`,这个数就是 Alice 和 Bob 共有的秘密。 79 | 80 | 而对于 Hack,可以窃取传输过程中的 `G`,`AG`,`BG`,但是由于计算不可逆,怎么都无法结合出 `ABG` 这个数字。 81 | 82 | ![](https://labuladong.github.io/pictures/密码技术/5.jpg) 83 | 84 | 以上就是基本流程,至于具体的数字取值是有讲究的,运算方法在百度上很容易找到,限于篇幅我就不具体写了。 85 | 86 | 该算法可以在第三者窃听的前提下,算出一个别人无法算出的秘密作为对称性加密算法的密钥,开始对称加密的通信。 87 | 88 | 对于该算法,Hack 又想到一种破解方法,不是窃听 Alice 和 Bob 的通信数据,而是直接同时冒充 Alice 和 Bob 的身份,也就是我们说的「**中间人攻击**」: 89 | 90 | ![](https://labuladong.github.io/pictures/密码技术/6.jpg) 91 | 92 | 这样,双方根本无法察觉在和 Hack 共享秘密,后果就是 Hack 可以解密甚至修改数据。 93 | 94 | **可见,密钥交换算法也不算完全解决了密钥配送问题,缺陷在于无法核实对方身份**。所以密钥交换算法之前一般要核实对方身份,比如使用数字签名。 95 | 96 | ### 三、非对称加密 97 | 98 | 非对称加密的思路就是,干脆别偷偷摸摸传输密钥了,我把加密密钥和解密密钥分开,公钥用于加密,私钥用于解密。只把公钥传送给对方,然后对方开始给我发送加密的数据,我用私钥就可以解密。至于窃听者,拿到公钥和加密数据也没用,因为只有我手上的私钥才能解密。 99 | 100 | 可以这样想,**私钥是钥匙,而公钥是锁,可以把锁公开出去,让别人把数据锁起来发给我;而钥匙一定要留在自己手里,用于解锁**。我们常见的 RSA 算法就是典型的非对称加密算法,具体实现比较复杂,我就不写了,网上很多资料。 101 | 102 | 在实际应用中,非对称性加密的运算速度要比对称性加密慢很多的,所以传输大量数据时,一般不会用公钥直接加密数据,而是加密对称性加密的密钥,传输给对方,然后双方使用对称性加密算法传输数据。 103 | 104 | 需要注意的是,类似 Diffie-Hellman 算法,**非对称加密算法也无法确定通信双方的身份,依然会遭到中间人攻击**。比如 Hack 拦截 Bob 发出的公钥,然后冒充 Bob 的身份给 Alice 发送自己的公钥,那么不知情的 Alice 就会把私密数据用 Hack 的公钥加密,Hack 可以通过私钥解密窃取。 105 | 106 | 那么,Diffie-Hellman 算法和 RSA 非对称加密算法都可以一定程度上解决密钥配送的问题,也具有相同的缺陷,二者的应用场景有什么区别呢? 107 | 108 | 简单来说,根据两种算法的基本原理就可以看出来: 109 | 110 | 如果双方有一个对称加密方案,希望加密通信,而且不能让别人得到钥匙,那么可以使用 Diffie-Hellman 算法交换密钥。 111 | 112 | 如果你希望任何人都可以对信息加密,而只有你能够解密,那么就使用 RSA 非对称加密算法,公布公钥。 113 | 114 | 下面,我们尝试着解决认证发送方身份的问题。 115 | 116 | ### 四、数字签名 117 | 118 | 刚才说非对称加密,把公钥公开用于他人对数据加密然后发给你,只有用你手上对应的私钥才能将密文解密。其实,**私钥也可用用来加密数据的,对于 RSA 算法,私钥加密的数据只有公钥才能解开**。 119 | 120 | 数字签名也是利用了非对称性密钥的特性,但是和公钥加密完全颠倒过来:**仍然公布公钥,但是用你的私钥加密数据,然后把加密的数据公布出去,这就是数字签名**。 121 | 122 | 你可能问,这有什么用,公钥可以解开私钥加密,我还加密发出去,不是多此一举吗? 123 | 124 | 是的,但是**数字签名的作用本来就不是保证数据的机密性,而是证明你的身份**,证明这些数据确实是由你本人发出的。 125 | 126 | 你想想,你的私钥加密的数据,只有你的公钥才能解开,那么如果一份加密数据能够被你的公钥解开,不就说明这份数据是你(私钥持有者)本人发布的吗? 127 | 128 | 当然,加密数据仅仅是一个签名,签名应该和数据一同发出,具体流程应该是: 129 | 130 | 1、Bob 生成公钥和私钥,然后把公钥公布出去,私钥自己保留。 131 | 132 | 2、**用私钥加密数据作为签名,然后将数据附带着签名一同发布出去**。 133 | 134 | 3、Alice 收到数据和签名,需要检查此份数据是否是 Bob 所发出,于是用 Bob 之前发出的公钥尝试解密签名,将收到的数据和签名解密后的结果作对比,如果完全相同,说明数据没被篡改,且确实由 Bob 发出。 135 | 136 | 为什么 Alice 这么肯定呢,毕竟数据和签名是两部分,都可以被掉包呀?原因如下: 137 | 138 | 1、如果有人修改了数据,那么 Alice 解密签名之后,对比发现二者不一致,察觉出异常。 139 | 140 | 2、如果有人替换了签名,那么 Alice 用 Bob 的公钥只能解出一串乱码,显然和数据不一致。 141 | 142 | 3、也许有人企图修改数据,然后将修改之后的数据制成签名,使得 Alice 的对比无法发现不一致;但是一旦解开签名,就不可能再重新生成 Bob 的签名了,因为没有 Bob 的私钥。 143 | 144 | 综上,**数字签名可以一定程度上认证数据的来源**。之所以说是一定程度上,是因为这种方式依然可能受到中间人攻击。一旦涉及公钥的发布,接收方就可能收到中间人的假公钥,进行错误的认证,这个问题始终避免不了。 145 | 146 | 说来可笑,数字签名就是验证对方身份的一种方式,但是前提是对方的身份必须是真的... 这似乎陷入一个先有鸡还是先有蛋的死循环,**要想确定对方的身份,必须有一个信任的源头,否则的话,再多的流程也只是在转移问题,而不是真正解决问题**。 147 | 148 | ### 五、公钥证书 149 | 150 | **证书其实就是公钥 + 签名,由第三方认证机构颁发**。引入可信任的第三方,是终结信任循环的一种可行方案。 151 | 152 | 证书认证的流程大致如下: 153 | 154 | 1、Bob 去可信任的认证机构证实本人真实身份,并提供自己的公钥。 155 | 156 | 2、Alice 想跟 Bob 通信,首先向认证机构请求 Bob 的公钥,认证机构会把一张证书(Bob 的公钥以及自己对其公钥的签名)发送给 Alice。 157 | 158 | 3、Alice 检查签名,确定该公钥确实由这家认证机构发送,中途未被篡改。 159 | 160 | 4、Alice 通过这个公钥加密数据,开始和 Bob 通信。 161 | 162 | ![](https://labuladong.github.io/pictures/密码技术/7.jpg) 163 | 164 | > note:以上只是为了说明,证书只需要安装一次,并不需要每次都向认证机构请求;一般是服务器直接给客户端发送证书,而不是认证机构。 165 | 166 | 也许有人问,Alice 要想通过数字签名确定证书的有效性,前提是要有该机构的(认证)公钥,这不是又回到刚才的死循环了吗? 167 | 168 | 我们安装的正规浏览器中都预存了正规认证机构的证书(包含其公钥),用于确认机构身份,所以说证书的认证是可信的。 169 | 170 | Bob 向机构提供公钥的过程中,需要提供很多个人信息进行身份验证,比较严格,所以说也算是可靠的。 171 | 172 | 获得了 Bob 的可信公钥,Alice 和 Bob 之间的通信基于加密算法的保护,是完全无懈可击的。 173 | 174 | 现在的正规网站,大都使用 HTTPS 协议,就是在 HTTP 协议和 TCP 协议之间加了一个 SSL/TLS 安全层。在你的浏览器和网站服务器完成 TCP 握手后,SSL 协议层也会进行 SSL 握手交换安全参数,其中就包含该网站的证书,以便浏览器验证站点身份。SSL 安全层验证完成之后,上层的 HTTP 协议内容都会被加密,保证数据的安全传输。 175 | 176 | 这样一来,传统的中间人攻击就几乎没有了生存空间,攻击手段只能由技术缺陷转变为坑蒙拐骗。事实上,这种手段的效果反而更高效,比如我就发现**网上不少下载网站发布的浏览器,不仅包含乱七八糟的导航和收藏网址,还包含一些不正规的认证机构证书。任何人都可以申请证书,这些不正规证书很可能造成安全隐患**。 177 | 178 | ### 六、最后总结 179 | 180 | 对称性加密算法使用同一个密钥加密和解密,难以破解,加密速度较快,但是存在密钥配送问题。 181 | 182 | Diffie-Hellman 密钥交换算法可以让双方「心有灵犀一点通」,一定程度解决密钥配送问题,但是无法验证通信方的身份,所以可能受到中间人攻击。 183 | 184 | 非对称性加密算法生成一对儿密钥,把加密和解密的工作分开了。 185 | 186 | RSA 算法作为经典的非对称加密算法,有两种用途:如果用于加密,可以把公钥发布出去用于加密,只有自己的私钥可以解密,保证了数据的机密性;如果用于数字签名,把公钥发布出去后,用私钥加密数据作为签名,以证明该数据由私钥持有者所发送。但是无论那种用法,涉及公钥的发布,都无法避免中间人攻击。 187 | 188 | 公钥证书就是公钥 + 签名,由可信任的第三方认证机构颁发。由于正规浏览器都预装了可信的认证机构的公钥,所以可以有效防止中间人攻击。 189 | 190 | HTTPS 协议中的 SSL/TLS 安全层会组合使用以上几种加密方式,**所以说不要安装非正规的浏览器,不要乱安装未知来源的证书**。 191 | 192 | 密码技术只是安全的一小部分,即便是通过正规机构认证的 HTTPS 站点,也不意味着可信任,只能说明其数据传输是安全的。技术永远不可能真正保护你,最重要的还是得提高个人的安全防范意识,多留心眼儿,谨慎处理敏感数据。 193 | 194 | 195 | 196 | 197 | 198 | **_____________** 199 | 200 | **《labuladong 的算法小抄》已经出版,关注公众号查看详情;后台回复「**全家桶**」可下载配套 PDF 和刷题全家桶**: 201 | 202 | ![](https://labuladong.github.io/pictures/souyisou2.png) 203 | 204 | ======其他语言代码====== -------------------------------------------------------------------------------- /数据结构系列/README.md: -------------------------------------------------------------------------------- 1 | # 数据结构系列 2 | 3 | 这一章主要是一些特殊的数据结构设计,比如单调栈解决 Next Greater Number,单调队列解决滑动窗口问题;还有常用数据结构的操作,比如链表、树、二叉堆。 4 | 5 | 欢迎关注我的公众号 labuladong,查看全部文章: 6 | 7 | ![labuladong二维码](../pictures/qrcode.jpg) -------------------------------------------------------------------------------- /算法思维系列/BFS解决滑动拼图.md: -------------------------------------------------------------------------------- 1 | # BFS 算法秒杀各种益智游戏 2 | 3 |

4 | GitHub 5 | 6 | 7 | 8 |

9 | 10 | ![](https://labuladong.github.io/pictures/souyisou1.png) 11 | 12 | **通知:[数据结构精品课](https://aep.h5.xeknow.com/s/1XJHEO) 和 [递归算法专题课](https://aep.xet.tech/s/3YGcq3) 限时附赠网站会员,全新纸质书[《labuladong 的算法笔记》](https://labuladong.gitee.io/algo/images/book/book_intro_qrcode.jpg) 出版,签名版限时半价!另外,建议你在我的 [网站](https://labuladong.github.io/algo/) 学习文章,体验更好。** 13 | 14 | 15 | 16 | 读完本文,你不仅学会了算法套路,还可以顺便解决如下题目: 17 | 18 | | LeetCode | 力扣 | 难度 | 19 | | :----: | :----: | :----: | 20 | | [773. Sliding Puzzle](https://leetcode.com/problems/sliding-puzzle/) | [773. 滑动谜题](https://leetcode.cn/problems/sliding-puzzle/) | 🔴 21 | 22 | **-----------** 23 | 24 | 滑动拼图游戏大家应该都玩过,下图是一个 4x4 的滑动拼图: 25 | 26 | ![](https://labuladong.github.io/pictures/sliding_puzzle/1.jpeg) 27 | 28 | 拼图中有一个格子是空的,可以利用这个空着的格子移动其他数字。你需要通过移动这些数字,得到某个特定排列顺序,这样就算赢了。 29 | 30 | 我小时候还玩过一款叫做「华容道」的益智游戏,也和滑动拼图比较类似: 31 | 32 | ![](https://labuladong.github.io/pictures/sliding_puzzle/2.jpeg) 33 | 34 | 实际上,滑动拼图游戏也叫数字华容道,你看它俩挺相似的。 35 | 36 | 那么这种游戏怎么玩呢?我记得是有一些套路的,类似于魔方还原公式。但是我们今天不来研究让人头秃的技巧,**这些益智游戏通通可以用暴力搜索算法解决,所以今天我们就学以致用,用 BFS 算法框架来秒杀这些游戏**。 37 | 38 | ### 一、题目解析 39 | 40 | 力扣第 773 题「滑动谜题」就是这个问题,题目的要求如下: 41 | 42 | 给你一个 2x3 的滑动拼图,用一个 2x3 的数组 `board` 表示。拼图中有数字 0~5 六个数,其中**数字 0 就表示那个空着的格子**,你可以移动其中的数字,当 `board` 变为 `[[1,2,3],[4,5,0]]` 时,赢得游戏。 43 | 44 | 请你写一个算法,计算赢得游戏需要的最少移动次数,如果不能赢得游戏,返回 -1。 45 | 46 | 比如说输入的二维数组 `board = [[4,1,2],[5,0,3]]`,算法应该返回 5: 47 | 48 | ![](https://labuladong.github.io/pictures/sliding_puzzle/5.jpeg) 49 | 50 | 如果输入的是 `board = [[1,2,3],[5,4,0]]`,则算法返回 -1,因为这种局面下无论如何都不能赢得游戏。 51 | 52 | ### 二、思路分析 53 | 54 | 对于这种计算最小步数的问题,我们就要敏感地想到 BFS 算法。 55 | 56 | 这个题目转化成 BFS 问题是有一些技巧的,我们面临如下问题: 57 | 58 | 1、一般的 BFS 算法,是从一个起点 `start` 开始,向终点 `target` 进行寻路,但是拼图问题不是在寻路,而是在不断交换数字,这应该怎么转化成 BFS 算法问题呢? 59 | 60 | 2、即便这个问题能够转化成 BFS 问题,如何处理起点 `start` 和终点 `target`?它们都是数组哎,把数组放进队列,套 BFS 框架,想想就比较麻烦且低效。 61 | 62 | 首先回答第一个问题,**BFS 算法并不只是一个寻路算法,而是一种暴力搜索算法**,只要涉及暴力穷举的问题,BFS 就可以用,而且可以最快地找到答案。 63 | 64 | 你想想计算机怎么解决问题的?哪有什么特殊技巧,本质上就是把所有可行解暴力穷举出来,然后从中找到一个最优解罢了。 65 | 66 | 明白了这个道理,我们的问题就转化成了:**如何穷举出 `board` 当前局面下可能衍生出的所有局面**?这就简单了,看数字 0 的位置呗,和上下左右的数字进行交换就行了: 67 | 68 | ![](https://labuladong.github.io/pictures/sliding_puzzle/3.jpeg) 69 | 70 | 这样其实就是一个 BFS 问题,每次先找到数字 0,然后和周围的数字进行交换,形成新的局面加入队列…… 当第一次到达 `target` 时,就得到了赢得游戏的最少步数。 71 | 72 | 对于第二个问题,我们这里的 `board` 仅仅是 2x3 的二维数组,所以可以压缩成一个一维字符串。**其中比较有技巧性的点在于,二维数组有「上下左右」的概念,压缩成一维后,如何得到某一个索引上下左右的索引**? 73 | 74 | 对于这道题,题目说输入的数组大小都是 2 x 3,所以我们可以直接手动写出来这个映射: 75 | 76 | 77 | ```java 78 | // 记录一维字符串的相邻索引 79 | int[][] neighbor = new int[][]{ 80 | {1, 3}, 81 | {0, 4, 2}, 82 | {1, 5}, 83 | {0, 4}, 84 | {3, 1, 5}, 85 | {4, 2} 86 | }; 87 | ``` 88 | 89 | **这个含义就是,在一维字符串中,索引 `i` 在二维数组中的的相邻索引为 `neighbor[i]`**: 90 | 91 | ![](https://labuladong.github.io/pictures/sliding_puzzle/4.jpeg) 92 | 93 | 那么对于一个 `m x n` 的二维数组,手写它的一维索引映射肯定不现实了,如何用代码生成它的一维索引映射呢? 94 | 95 | 观察上图就能发现,如果二维数组中的某个元素 `e` 在一维数组中的索引为 `i`,那么 `e` 的左右相邻元素在一维数组中的索引就是 `i - 1` 和 `i + 1`,而 `e` 的上下相邻元素在一维数组中的索引就是 `i - n` 和 `i + n`,其中 `n` 为二维数组的列数。 96 | 97 | 这样,对于 `m x n` 的二维数组,我们可以写一个函数来生成它的 `neighbor` 索引映射: 98 | 99 | ```java 100 | int[][] generateNeighborMapping(int m, int n) { 101 | int[][] neighbor = new int[m * n][]; 102 | for (int i = 0; i < m * n; i++) { 103 | List neighbors = new ArrayList<>(); 104 | 105 | // 如果不是第一列,有左侧邻居 106 | if (i % n != 0) neighbors.add(i - 1); 107 | // 如果不是最后一列,有右侧邻居 108 | if (i % n != n - 1) neighbors.add(i + 1); 109 | // 如果不是第一行,有上方邻居 110 | if (i - n >= 0) neighbors.add(i - n); 111 | // 如果不是最后一行,有下方邻居 112 | if (i + n < m * n) neighbors.add(i + n); 113 | 114 | // Java 语言特性,将 List 类型转为 int[] 数组 115 | neighbor[i] = neighbors.stream().mapToInt(Integer::intValue).toArray(); 116 | } 117 | return neighbor; 118 | } 119 | ``` 120 | 121 | 至此,我们就把这个问题完全转化成标准的 BFS 问题了,借助前文 [BFS 算法框架](https://labuladong.github.io/article/fname.html?fname=BFS框架) 的代码框架,直接就可以套出解法代码了: 122 | 123 | 124 | ```java 125 | class Solution { 126 | public int slidingPuzzle(int[][] board) { 127 | int m = 2, n = 3; 128 | StringBuilder sb = new StringBuilder(); 129 | String target = "123450"; 130 | // 将 2x3 的数组转化成字符串作为 BFS 的起点 131 | for (int i = 0; i < m; i++) { 132 | for (int j = 0; j < n; j++) { 133 | sb.append(board[i][j]); 134 | } 135 | } 136 | String start = sb.toString(); 137 | 138 | // 记录一维字符串的相邻索引 139 | int[][] neighbor = new int[][]{ 140 | {1, 3}, 141 | {0, 4, 2}, 142 | {1, 5}, 143 | {0, 4}, 144 | {3, 1, 5}, 145 | {4, 2} 146 | }; 147 | 148 | /******* BFS 算法框架开始 *******/ 149 | Queue q = new LinkedList<>(); 150 | HashSet visited = new HashSet<>(); 151 | // 从起点开始 BFS 搜索 152 | q.offer(start); 153 | visited.add(start); 154 | 155 | int step = 0; 156 | while (!q.isEmpty()) { 157 | int sz = q.size(); 158 | for (int i = 0; i < sz; i++) { 159 | String cur = q.poll(); 160 | // 判断是否达到目标局面 161 | if (target.equals(cur)) { 162 | return step; 163 | } 164 | // 找到数字 0 的索引 165 | int idx = 0; 166 | for (; cur.charAt(idx) != '0'; idx++) ; 167 | // 将数字 0 和相邻的数字交换位置 168 | for (int adj : neighbor[idx]) { 169 | String new_board = swap(cur.toCharArray(), adj, idx); 170 | // 防止走回头路 171 | if (!visited.contains(new_board)) { 172 | q.offer(new_board); 173 | visited.add(new_board); 174 | } 175 | } 176 | } 177 | step++; 178 | } 179 | /******* BFS 算法框架结束 *******/ 180 | return -1; 181 | } 182 | 183 | private String swap(char[] chars, int i, int j) { 184 | char temp = chars[i]; 185 | chars[i] = chars[j]; 186 | chars[j] = temp; 187 | return new String(chars); 188 | } 189 | } 190 | ``` 191 | 192 | 193 | 194 | 至此,这道题目就解决了,其实框架完全没有变,套路都是一样的,我们只是花了比较多的时间将滑动拼图游戏转化成 BFS 算法。 195 | 196 | 很多益智游戏都是这样,虽然看起来特别巧妙,但都架不住暴力穷举,常用的算法就是回溯算法或者 BFS 算法。 197 | 198 | 199 | 200 |
201 |
202 | 引用本文的文章 203 | 204 | - [BFS 算法解题套路框架](https://labuladong.github.io/article/fname.html?fname=BFS框架) 205 | 206 |

207 | 208 | 209 | 210 | 211 |
212 |
213 | 引用本文的题目 214 | 215 | 安装 [我的 Chrome 刷题插件](https://labuladong.github.io/article/fname.html?fname=chrome插件简介) 点开下列题目可直接查看解题思路: 216 | 217 | | LeetCode | 力扣 | 218 | | :----: | :----: | 219 | | [365. Water and Jug Problem](https://leetcode.com/problems/water-and-jug-problem/?show=1) | [365. 水壶问题](https://leetcode.cn/problems/water-and-jug-problem/?show=1) | 220 | 221 |
222 |
223 | 224 | 225 | 226 | **_____________** 227 | 228 | **《labuladong 的算法小抄》已经出版,关注公众号查看详情;后台回复「**全家桶**」可下载配套 PDF 和刷题全家桶**: 229 | 230 | ![](https://labuladong.github.io/pictures/souyisou2.png) -------------------------------------------------------------------------------- /算法思维系列/README.md: -------------------------------------------------------------------------------- 1 | # 算法思维系列 2 | 3 | 本章包含一些常用的算法技巧,比如前缀和、回溯思想、位操作、双指针、如何正确书写二分查找等等。 4 | 5 | 欢迎关注我的公众号 labuladong,查看全部文章: 6 | 7 | ![labuladong二维码](../pictures/table_qr2.jpg) 8 | ![labuladong二维码](../pictures/qrcode.jpg) -------------------------------------------------------------------------------- /算法思维系列/几个反直觉的概率问题.md: -------------------------------------------------------------------------------- 1 | # 几个反直觉的概率问题 2 | 3 |

4 | GitHub 5 | 6 | 7 | 8 |

9 | 10 | ![](https://labuladong.github.io/pictures/souyisou1.png) 11 | 12 | **通知:[数据结构精品课](https://aep.h5.xeknow.com/s/1XJHEO) 和 [递归算法专题课](https://aep.xet.tech/s/3YGcq3) 限时附赠网站会员,全新纸质书[《labuladong 的算法笔记》](https://labuladong.gitee.io/algo/images/book/book_intro_qrcode.jpg) 出版,签名版限时半价!另外,建议你在我的 [网站](https://labuladong.github.io/algo/) 学习文章,体验更好。** 13 | 14 | 15 | 16 | **-----------** 17 | 18 | 上篇文章 [谈谈游戏中的随机算法](https://labuladong.github.io/article/fname.html?fname=随机算法) 讲到了验证概率算法的蒙特卡罗方法,今天聊点轻松的内容:几个和概率相关的有趣问题。 19 | 20 | 计算概率有下面两个最简单的原则: 21 | 22 | 原则一、计算概率一定要有一个参照系,称作「样本空间」,即随机事件可能出现的所有结果。事件 A 发生的概率 = A 包含的样本点 / 样本空间的样本总数。 23 | 24 | 原则二、计算概率一定要明白,概率是一个连续的整体,不可以把连续的概率分割开,也就是所谓的条件概率。 25 | 26 | 上述两个原则高中就学过,但是我们还是很容易犯错,而且犯错的流程也有异曲同工之妙: 27 | 28 | 先是忽略了原则二,错误地计算了样本空间,然后通过原则一算出了错误的答案。 29 | 30 | 下面介绍几个简单却具有迷惑性的问题,分别是男孩女孩问题、生日悖论、三门问题。当然,三门问题可能是大家最耳熟的,所以就多说一些有趣的思考。 31 | 32 | ### 一、男孩女孩问题 33 | 34 | 假设有一个家庭,有两个孩子,现在告诉你其中有一个男孩,请问另一个也是男孩的概率是多少? 35 | 36 | 很多人,包括我在内,不假思索地回答:1/2 啊,因为另一个孩子要么是男孩,要么是女孩,而且概率相等呀。但是实际上,答案是 1/3。 37 | 38 | 上述思想为什么错误呢?因为没有正确计算样本空间,导致原则一计算错误。有两个孩子,那么样本空间为 4,即哥哥妹妹,哥哥弟弟,姐姐妹妹,姐姐弟弟这四种情况。已知有一个男孩,那么排除姐姐妹妹这种情况,所以样本空间变成 3。另一个孩子也是男孩只有哥哥弟弟这 1 种情况,所以概率为 1/3。 39 | 40 | 为什么计算样本空间会出错呢?因为我们忽略了条件概率,即混淆了下面两个问题: 41 | 42 | 这个家庭只有一个孩子,这个孩子是男孩的概率是多少? 43 | 44 | 这个家庭有两个孩子,其中一个是男孩,另一个孩子是男孩的概率是多少? 45 | 46 | 根据原则二,概率问题是连续的,不可以把上述两个问题混淆。第二个问题需要用条件概率,即求一个孩子是男孩的条件下,另一个也是男孩的概率。运用条件概率的公式也很好算,就不多说了。 47 | 48 | 通过这个问题,读者应该理解两个概率计算原则的关系了,最具有迷惑性的就是条件概率的忽视。为了不要被迷惑,最简单的办法就是把所有可能结果穷举出来。 49 | 50 | 最后,对于此问题我见过一个很奇葩的质疑:如果这两个孩子是双胞胎,不存在年龄上的差异怎么办? 51 | 52 | 我竟然觉得有那么一丝道理!但其实,我们只是通过年龄差异来表示两个孩子的独立性,也就是说即便两个孩子同性,也有两种可能。所以不要用双胞胎抬杠了。 53 | 54 | ### 二、生日悖论 55 | 56 | 生日悖论是由这样一个问题引出的:一个屋子里需要有多少人,才能使得存在至少两个人生日是同一天的概率达到 50%? 57 | 58 | 答案是 23 个人,也就是说房子里如果有 23 个人,那么就有 50% 的概率会存在两个人生日相同。这个结论看起来不可思议,所以被称为悖论。按照直觉,要得到 50% 的概率,起码得有 183 个人吧,因为一年有 365 天呀?其实不是的,觉得这个结论不可思议主要有两个思维误区: 59 | 60 | **第一个误区是误解「存在」这个词的含义**。 61 | 62 | 读者可能认为,如果 23 个人中出现相同生日的概率就能达到 50%,是不是意味着: 63 | 64 | 假设现在屋子里坐着 22 个人,然后我走进去,那么有 50% 的概率我可以找到一个人和我生日相同。但这怎么可能呢? 65 | 66 | 并不是的,你这种想法是以自我为中心,而题目的概率是在描述整体。也就是说「存在」的含义是指 23 人中的任意两个人,涉及排列组合,大概率和你没啥关系。 67 | 68 | 如果你非要计算存在和自己生日相同的人的概率是多少,可以这样计算: 69 | 70 | 1 - P(22 个人都和我的生日不同) = 1 -(364/365)^22 = 0.06 71 | 72 | 这样计算得到的结果是不是看起来合理多了?生日悖论计算对象的不是某一个人,而是一个整体,其中包含了所有人的排列组合,它们的概率之和当然会大得多。 73 | 74 | **第二个误区是认为概率是线性变化的**。 75 | 76 | 读者可能认为,如果 23 个人中出现相同生日的概率就能达到 50%,是不是意味着 46 个人的概率就能达到 100%? 77 | 78 | 不是的,就像中奖率 50% 的游戏,你玩两次的中奖率就是 100% 吗?显然不是,你玩两次的中奖率是 75%: 79 | 80 | `P(两次能中奖) = P(第一次就中了) + P(第一次没中但第二次中了) = 1/2 + 1/2*1/2 = 75%` 81 | 82 | 那么换到生日悖论也是一个道理,概率不是简单叠加,而要考虑一个连续的过程,所以这个结论并没有什么不合常理之处。 83 | 84 | 那为什么只要 23 个人出现相同生日的概率就能大于 50% 了呢?我们先计算 23 个人生日都唯一(不重复)的概率。只有 1 个人的时候,生日唯一的概率是 `365/365`,2 个人时,生日唯一的概率是 `365/365 × 364/365`,以此类推可知 23 人的生日都唯一的概率: 85 | 86 | ![](https://labuladong.github.io/pictures/概率问题/p.png) 87 | 88 | 算出来大约是 0.493,所以存在相同生日的概率就是 0.507,差不多就是 50% 了。实际上,按照这个算法,当人数达到 70 时,存在两个人生日相同的概率就上升到了 99.9%,基本可以认为是 100% 了。所以从概率上说,一个几十人的小团体中存在生日相同的人真没啥稀奇的。 89 | 90 | ### 三、三门问题 91 | 92 | 这个游戏很经典了:游戏参与者面对三扇门,其中两扇门后面是山羊,一扇门后面是跑车。参与者只要随便选一扇门,门后面的东西就归他(跑车的价值当然更大)。但是主持人决定帮一下参与者:在他选择之后,先不急着打开这扇门,而是由主持人打开剩下两扇门中的一扇,展示其中的山羊(主持人知道每扇门后面是什么),然后给参与者一次换门的机会,此时参与者应该换门还是不换门呢? 93 | 94 | 为了防止第一次看到这个问题的读者迷惑,再具体描述一下这个问题: 95 | 96 | 你是游戏参与者,现在有门 1,2,3,假设你随机选择了门 1,然后主持人打开了门 3 告诉你那后面是山羊。现在,你是坚持你最初的选择门 1,还是选择换成门 2 呢? 97 | 98 | ![](https://labuladong.github.io/pictures/概率问题/sanmen.png) 99 | 100 | 答案是应该换门,换门之后抽到跑车的概率是 2/3,不换的话是 1/3。又一次反直觉,感觉换不换的中奖概率应该都一样啊,因为最后肯定就剩两个门,一个是羊,一个是跑车,这是事实,所以不管选哪个的概率不都是 1/2 吗? 101 | 102 | 类似前面说的男孩女孩问题,最简单稳妥的方法就是把所有可能结果穷举出来: 103 | 104 | ![](https://labuladong.github.io/pictures/概率问题/tree.png) 105 | 106 | 很容易看到选择换门中奖的概率是 2/3,不换的话是 1/3。 107 | 108 | 关于这个问题还有更简单的方法:主持人开门实际上在「浓缩」概率。一开始你选择到跑车的概率当然是 1/3,剩下两个门中包含跑车的概率当然是 2/3,这没啥可说的。但是主持人帮你排除了一个含有山羊的门,相当于把那 2/3 的概率浓缩到了剩下的这一扇门上。那么,你说你是抱着原来那扇 1/3 的门,还是换成那扇经过「浓缩」的 2/3 概率的门呢? 109 | 110 | 再直观一点,假设你三选一,剩下 2 扇门,再给你加入 98 扇装山羊的门,把这 100 扇门随机打乱,问你换不换?肯定不换对吧,这明摆着把概率稀释了,肯定抱着原来的那扇门是最可能中跑车的。再假设,初始有 100 扇门,你选了一扇,然后主持人在剩下 99 扇门中帮你排除 98 个山羊,问你换不换一扇门?肯定换对吧,你手上那扇门是 1%,另一扇门是 99%,或者也可以这样理解,不换只是选择了 1 扇门,换门相当于选择了 99 扇门,这样结果很明显了吧? 111 | 112 | 以上思想,也许有的读者都思考过,下面我们思考这样一个问题:假设你在决定是否换门的时候,小明破门而入,要求帮你做出选择。他完全不知道之前发生的事,他只知道面前有两扇门,一扇是跑车一扇是山羊,那么他抽中跑车的概率是多大? 113 | 114 | 当然是 1/2,这也是很多人做错三门问题的根本原因。类似生日悖论,人们总是容易以自我为中心,通过这个小明的视角来计算是否换门,这显然会进入误区。 115 | 116 | 就好比有两个箱子,一号箱子有 4 个黑球 2 个红球,二号箱子有 2 个黑球 4 个红球,随便选一个箱子,随便摸一个球,问你摸出红球的概率。 117 | 118 | 对于不知情的小明,他会随机选择一个箱子,随机摸球,摸到红球的概率是:1/2 × 2/6 + 1/2 × 4/6 = 1/2 119 | 120 | 对于知情的你,你知道在二号箱子摸球概率大,所以只在二号箱摸,摸到红球的概率是:0 × 2/6 + 1 × 4/6 = 2/3 121 | 122 | 三门问题是有指导意义的。比如你蒙选择题,先蒙了 A,后来灵机一动排除了 B 和 C,请问你是否要把 A 换成 D?答案是,换! 123 | 124 | 也许读者会问,如果只排除了一个答案,比如说 B,那么我是否应该把 A 换成 C 或者 D 呢?答案是,换! 125 | 126 | 因为按照刚才「浓缩」概率这个思想,只要进行了排除,都是在进行「浓缩」,均摊下来肯定比你一开始蒙的那个答案概率 1/4 高。比如刚才的例子,C 和 D 的正确概率都是 3/8,而你开始蒙的 A 只有 1/4。 127 | 128 | 当然,运用此策略蒙题的前提是你真的抓瞎,真的随机乱选答案,这样概率才能作为最后的杀手锏。 129 | 130 | 131 | 132 | 133 | 134 | **_____________** 135 | 136 | **《labuladong 的算法小抄》已经出版,关注公众号查看详情;后台回复「**全家桶**」可下载配套 PDF 和刷题全家桶**: 137 | 138 | ![](https://labuladong.github.io/pictures/souyisou2.png) 139 | 140 | ======其他语言代码====== -------------------------------------------------------------------------------- /算法思维系列/字符串乘法.md: -------------------------------------------------------------------------------- 1 | # 字符串乘法 2 | 3 |

4 | GitHub 5 | 6 | 7 | 8 |

9 | 10 | ![](https://labuladong.github.io/pictures/souyisou1.png) 11 | 12 | **通知:[数据结构精品课](https://aep.h5.xeknow.com/s/1XJHEO) 和 [递归算法专题课](https://aep.xet.tech/s/3YGcq3) 限时附赠网站会员,全新纸质书[《labuladong 的算法笔记》](https://labuladong.gitee.io/algo/images/book/book_intro_qrcode.jpg) 出版,签名版限时半价!另外,建议你在我的 [网站](https://labuladong.github.io/algo/) 学习文章,体验更好。** 13 | 14 | 15 | 16 | 读完本文,你不仅学会了算法套路,还可以顺便解决如下题目: 17 | 18 | | LeetCode | 力扣 | 难度 | 19 | | :----: | :----: | :----: | 20 | | [43. Multiply Strings](https://leetcode.com/problems/multiply-strings/) | [43. 字符串相乘](https://leetcode.cn/problems/multiply-strings/) | 🟠 21 | 22 | **-----------** 23 | 24 | 对于比较小的数字,做运算可以直接使用编程语言提供的运算符,但是如果相乘的两个因数非常大,语言提供的数据类型可能就会溢出。一种替代方案就是,运算数以字符串的形式输入,然后模仿我们小学学习的乘法算术过程计算出结果,并且也用字符串表示。 25 | 26 | 看下力扣第 43 题「字符串相乘」: 27 | 28 | 29 | 30 | 需要注意的是,`num1` 和 `num2` 可以非常长,所以不可以把他们直接转成整型然后运算,唯一的思路就是模仿我们手算乘法。 31 | 32 | 比如说我们手算 `123 × 45`,应该会这样计算: 33 | 34 | ![](https://labuladong.github.io/pictures/字符串乘法/1.jpg) 35 | 36 | 计算 `123 × 5`,再计算 `123 × 4`,最后错一位相加。这个流程恐怕小学生都可以熟练完成,但是你是否能**把这个运算过程进一步机械化**,写成一套算法指令让没有任何智商的计算机来执行呢? 37 | 38 | 你看这个简单过程,其中涉及乘法进位,涉及错位相加,还涉及加法进位;而且还有一些不易察觉的问题,比如说两位数乘以两位数,结果可能是四位数,也可能是三位数,你怎么想出一个标准化的处理方式?这就是算法的魅力,如果没有计算机思维,简单的问题可能都没办法自动化处理。 39 | 40 | 首先,我们这种手算方式还是太「高级」了,我们要再「低级」一点,`123 × 5` 和 `123 × 4` 的过程还可以进一步分解,最后再相加: 41 | 42 | ![](https://labuladong.github.io/pictures/字符串乘法/2.jpg) 43 | 44 | 现在 `123` 并不大,如果是个很大的数字的话,是无法直接计算乘积的。我们可以用一个数组在底下接收相加结果: 45 | 46 | ![](https://labuladong.github.io/pictures/字符串乘法/3.jpg) 47 | 48 | 整个计算过程大概是这样,**有两个指针 `i,j` 在 `num1` 和 `num2` 上游走,计算乘积,同时将乘积叠加到 `res` 的正确位置**,如下 GIF 图所示: 49 | 50 | ![](https://labuladong.github.io/pictures/字符串乘法/4.gif) 51 | 52 | 现在还有一个关键问题,如何将乘积叠加到 `res` 的正确位置,或者说,如何通过 `i,j` 计算 `res` 的对应索引呢? 53 | 54 | 其实,细心观察之后就发现,**`num1[i]` 和 `num2[j]` 的乘积对应的就是 `res[i+j]` 和 `res[i+j+1]` 这两个位置**。 55 | 56 | ![](https://labuladong.github.io/pictures/字符串乘法/6.jpg) 57 | 58 | 明白了这一点,就可以用代码模仿出这个计算过程了: 59 | 60 | 61 | ```cpp 62 | string multiply(string num1, string num2) { 63 | int m = num1.size(), n = num2.size(); 64 | // 结果最多为 m + n 位数 65 | vector res(m + n, 0); 66 | // 从个位数开始逐位相乘 67 | for (int i = m - 1; i >= 0; i--) 68 | for (int j = n - 1; j >= 0; j--) { 69 | int mul = (num1[i]-'0') * (num2[j]-'0'); 70 | // 乘积在 res 对应的索引位置 71 | int p1 = i + j, p2 = i + j + 1; 72 | // 叠加到 res 上 73 | int sum = mul + res[p2]; 74 | res[p2] = sum % 10; 75 | res[p1] += sum / 10; 76 | } 77 | // 结果前缀可能存的 0(未使用的位) 78 | int i = 0; 79 | while (i < res.size() && res[i] == 0) 80 | i++; 81 | // 将计算结果转化成字符串 82 | string str; 83 | for (; i < res.size(); i++) 84 | str.push_back('0' + res[i]); 85 | 86 | return str.size() == 0 ? "0" : str; 87 | } 88 | ``` 89 | 90 | 至此,字符串乘法算法就完成了。 91 | 92 | **总结一下**,我们习以为常的一些思维方式,在计算机看来是非常难以做到的。比如说我们习惯的算术流程并不复杂,但是如果让你再进一步,翻译成代码逻辑,并不简单。算法需要将计算流程再简化,通过边算边叠加的方式来得到结果。 93 | 94 | 俗话教育我们,不要陷入思维定式,不要程序化,要发散思维,要创新。但我觉得程序化并不是坏事,可以大幅提高效率,减小失误率。算法不就是一套程序化的思维吗,只有程序化才能让计算机帮助我们解决复杂问题呀! 95 | 96 | 也许算法就是一种**寻找思维定式的思维**吧,希望本文对你有帮助。 97 | 98 | 99 | 100 | 101 | 102 | **_____________** 103 | 104 | **《labuladong 的算法小抄》已经出版,关注公众号查看详情;后台回复「**全家桶**」可下载配套 PDF 和刷题全家桶**: 105 | 106 | ![](https://labuladong.github.io/pictures/souyisou2.png) 107 | 108 | ======其他语言代码====== 109 | 110 | [43.字符串相乘](https://leetcode-cn.com/problems/multiply-strings) 111 | 112 | 113 | 114 | ### python 115 | 116 | [fengshuu](https://github.com/fengshuu) 提供 Python 解法代码: 117 | ```python 118 | def multiply(num1: str, num2: str) -> str: 119 | m, n = len(num1), len(num2) 120 | # 结果最多为 m + n 位数 121 | res = [0] * (m + n) 122 | # 从个位数开始逐位相乘 123 | for i in range(m-1, -1, -1): 124 | for j in range(n-1, -1, -1): 125 | mul = int(num1[i]) * int(num2[j]) 126 | # 乘积在 res 对应的索引位置 127 | p1 = i + j 128 | p2 = i + j + 1 129 | # 叠加到 res 上 130 | digit_sum = mul + res[p2] 131 | res[p2] = digit_sum % 10 132 | res[p1] += digit_sum // 10 133 | 134 | # 结果前缀可能存的 0(未使用的位) 135 | i = 0 136 | while i < len(res) and res[i] == 0: 137 | i += 1 138 | 139 | # 将计算结果转化成字符串 140 | result_str = "".join(str(x) for x in res[i:]) 141 | 142 | return "0" if len(result_str) == 0 else result_str 143 | ``` 144 | 145 | ### java 146 | 147 | [Zane Wang](https://github.com/zanecat) 提供 Java 解法代码: 148 | ```java 149 | public String multiply(String num1, String num2) { 150 | // 初始化字符数组 151 | char[] s1 = num1.toCharArray(); 152 | char[] s2 = num2.toCharArray(); 153 | 154 | // 结果长度最多为两字符串长度之和 155 | int[] res = new int[s1.length + s2.length]; 156 | 157 | // 从个位开始遍历,把两数字中每一位相乘 158 | for (int i = s1.length - 1; i >= 0; i--) { 159 | for (int j = s2.length - 1; j >= 0; j--) { 160 | // 计算乘积,并把乘积放在 res 对应的位置, 暂时不考虑进位 161 | res[i + j + 1] += (s1[i] - '0') * (s2[j] - '0'); 162 | } 163 | } 164 | 165 | // 从个位再次遍历,如果上一次遍历中两数乘积为两位数,进位并叠加到前面一位 166 | int carry = 0; 167 | for (int i = res.length - 1; i >= 0; i--) { 168 | int sum = res[i] + carry; 169 | res[i] = sum % 10; 170 | carry = sum / 10; 171 | } 172 | 173 | //遍历res数组,构造最终答案字符串 174 | StringBuilder ans = new StringBuilder(); 175 | int i = 0; 176 | 177 | // 首先找到不为0的第一位 178 | while (i < res.length - 1 && res[i] == 0) { 179 | i++; 180 | } 181 | 182 | // 将后面的数字附加到ans后面 183 | while (i < res.length) { 184 | ans.append(res[i++]); 185 | } 186 | return ans.toString(); 187 | } 188 | ``` 189 | 190 | 191 | 192 | ### javascript 193 | 194 | ```js 195 | /** 196 | * @param {string} num1 197 | * @param {string} num2 198 | * @return {string} 199 | */ 200 | const multiply = (num1, num2) => { 201 | const m = num1.length; 202 | const n = num2.length; 203 | const pos = new Array(m + n).fill(0); 204 | 205 | for (let i = m - 1; i >= 0; i--) { 206 | const n1 = +num1[i]; 207 | for (let j = n - 1; j >= 0; j--) { 208 | const n2 = +num2[j]; 209 | const multi = n1 * n2; 210 | const sum = pos[i + j + 1] + multi; 211 | 212 | pos[i + j + 1] = sum % 10; 213 | pos[i + j] += sum / 10 | 0; 214 | } 215 | } 216 | while (pos[0] === 0) { 217 | pos.shift(); 218 | } 219 | return pos.length ? pos.join('') : '0'; 220 | }; 221 | ``` 222 | 223 | -------------------------------------------------------------------------------- /高频面试系列/README.md: -------------------------------------------------------------------------------- 1 | # 高频面试系列 2 | 3 | 8 说了,本章都是高频面试题,配合前面的动态规划系列,祝各位马到成功! 4 | 5 | 欢迎关注我的公众号 labuladong,查看全部文章: 6 | 7 | ![labuladong二维码](../pictures/qrcode.jpg) -------------------------------------------------------------------------------- /高频面试系列/二分运用.md: -------------------------------------------------------------------------------- 1 | # 二分查找的实际运用 2 | 3 |

4 | GitHub 5 | 6 | 7 | 8 |

9 | 10 | ![](https://labuladong.github.io/pictures/souyisou1.png) 11 | 12 | **通知:[数据结构精品课](https://aep.h5.xeknow.com/s/1XJHEO) 和 [递归算法专题课](https://aep.xet.tech/s/3YGcq3) 限时附赠网站会员,全新纸质书[《labuladong 的算法笔记》](https://labuladong.gitee.io/algo/images/book/book_intro_qrcode.jpg) 出版,签名版限时半价!另外,建议你在我的 [网站](https://labuladong.github.io/algo/) 学习文章,体验更好。** 13 | 14 | 15 | 16 | 读完本文,你不仅学会了算法套路,还可以顺便解决如下题目: 17 | 18 | | LeetCode | 力扣 | 难度 | 19 | | :----: | :----: | :----: | 20 | | [1011. Capacity To Ship Packages Within D Days](https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/) | [1011. 在 D 天内送达包裹的能力](https://leetcode.cn/problems/capacity-to-ship-packages-within-d-days/) | 🟠 21 | | [410. Split Array Largest Sum](https://leetcode.com/problems/split-array-largest-sum/) | [410. 分割数组的最大值](https://leetcode.cn/problems/split-array-largest-sum/) | 🔴 22 | | [875. Koko Eating Bananas](https://leetcode.com/problems/koko-eating-bananas/) | [875. 爱吃香蕉的珂珂](https://leetcode.cn/problems/koko-eating-bananas/) | 🟠 23 | | - | [剑指 Offer II 073. 狒狒吃香蕉](https://leetcode.cn/problems/nZZqjQ/) | 🟠 24 | 25 | **-----------** 26 | 27 | 我们前文 [我写了首诗,把二分搜索变成了默写题](https://labuladong.github.io/article/fname.html?fname=二分查找详解) 详细介绍了二分搜索的细节问题,探讨了「搜索一个元素」,「搜索左侧边界」,「搜索右侧边界」这三个情况,教你如何写出正确无 bug 的二分搜索算法。 28 | 29 | **但是前文总结的二分搜索代码框架仅仅局限于「在有序数组中搜索指定元素」这个基本场景,具体的算法问题没有这么直接,可能你都很难看出这个问题能够用到二分搜索**。 30 | 31 | 所以本文就来总结一套二分搜索算法运用的框架套路,帮你在遇到二分搜索算法相关的实际问题时,能够有条理地思考分析,步步为营,写出答案。 32 | 33 | ### 原始的二分搜索代码 34 | 35 | 二分搜索的原型就是在「**有序数组**」中搜索一个元素 `target`,返回该元素对应的索引。 36 | 37 | 如果该元素不存在,那可以返回一个什么特殊值,这种细节问题只要微调算法实现就可实现。 38 | 39 | 还有一个重要的问题,如果「**有序数组**」中存在多个 `target` 元素,那么这些元素肯定挨在一起,这里就涉及到算法应该返回最左侧的那个 `target` 元素的索引还是最右侧的那个 `target` 元素的索引,也就是所谓的「搜索左侧边界」和「搜索右侧边界」,这个也可以通过微调算法的代码来实现。 40 | 41 | **我们前文 [我写了首诗,把二分搜索变成了默写题](https://labuladong.github.io/article/fname.html?fname=二分查找详解) 详细探讨了上述问题,对这块还不清楚的读者建议复习前文**,已经搞清楚基本二分搜索算法的读者可以继续看下去。 42 | 43 | **在具体的算法问题中,常用到的是「搜索左侧边界」和「搜索右侧边界」这两种场景**,很少有让你单独「搜索一个元素」。 44 | 45 | 因为算法题一般都让你求最值,比如让你求吃香蕉的「最小速度」,让你求轮船的「最低运载能力」,求最值的过程,必然是搜索一个边界的过程,所以后面我们就详细分析一下这两种搜索边界的二分算法代码。 46 | 47 | > note:注意,本文我写的都是左闭右开的二分搜索写法,如果你习惯两端都闭的写法,可以自行改写代码。 48 | 49 | 「搜索左侧边界」的二分搜索算法的具体代码实现如下: 50 | 51 | 52 | ```java 53 | // 搜索左侧边界 54 | int left_bound(int[] nums, int target) { 55 | if (nums.length == 0) return -1; 56 | int left = 0, right = nums.length; 57 | 58 | while (left < right) { 59 | int mid = left + (right - left) / 2; 60 | if (nums[mid] == target) { 61 | // 当找到 target 时,收缩右侧边界 62 | right = mid; 63 | } else if (nums[mid] < target) { 64 | left = mid + 1; 65 | } else if (nums[mid] > target) { 66 | right = mid; 67 | } 68 | } 69 | return left; 70 | } 71 | ``` 72 | 73 | 假设输入的数组 `nums = [1,2,3,3,3,5,7]`,想搜索的元素 `target = 3`,那么算法就会返回索引 2。 74 | 75 | 如果画一个图,就是这样: 76 | 77 | ![](https://labuladong.github.io/pictures/二分运用/1.jpeg) 78 | 79 | 「搜索右侧边界」的二分搜索算法的具体代码实现如下: 80 | 81 | 82 | ```java 83 | // 搜索右侧边界 84 | int right_bound(int[] nums, int target) { 85 | if (nums.length == 0) return -1; 86 | int left = 0, right = nums.length; 87 | 88 | while (left < right) { 89 | int mid = left + (right - left) / 2; 90 | if (nums[mid] == target) { 91 | // 当找到 target 时,收缩左侧边界 92 | left = mid + 1; 93 | } else if (nums[mid] < target) { 94 | left = mid + 1; 95 | } else if (nums[mid] > target) { 96 | right = mid; 97 | } 98 | } 99 | return left - 1; 100 | } 101 | ``` 102 | 103 | 输入同上,那么算法就会返回索引 4,如果画一个图,就是这样: 104 | 105 | ![](https://labuladong.github.io/pictures/二分运用/2.jpeg) 106 | 107 | 好,上述内容都属于复习,我想读到这里的读者应该都能理解。记住上述的图像,所有能够抽象出上述图像的问题,都可以使用二分搜索解决。 108 | 109 | 110 | 111 |
112 |
113 | 引用本文的文章 114 | 115 | - [丑数系列算法详解](https://labuladong.github.io/article/fname.html?fname=丑数) 116 | - [我写了首诗,把二分搜索算法变成了默写题](https://labuladong.github.io/article/fname.html?fname=二分查找详解) 117 | - [我的刷题心得](https://labuladong.github.io/article/fname.html?fname=算法心得) 118 | - [用算法打败算法](https://labuladong.github.io/article/fname.html?fname=PDF中的算法) 119 | - [经典动态规划:高楼扔鸡蛋](https://labuladong.github.io/article/fname.html?fname=高楼扔鸡蛋问题) 120 | - [讲两道常考的阶乘算法题](https://labuladong.github.io/article/fname.html?fname=阶乘题目) 121 | 122 |

123 | 124 | 125 | 126 | 127 |
128 |
129 | 引用本文的题目 130 | 131 | 安装 [我的 Chrome 刷题插件](https://labuladong.github.io/article/fname.html?fname=chrome插件简介) 点开下列题目可直接查看解题思路: 132 | 133 | | LeetCode | 力扣 | 134 | | :----: | :----: | 135 | | [1201. Ugly Number III](https://leetcode.com/problems/ugly-number-iii/?show=1) | [1201. 丑数 III](https://leetcode.cn/problems/ugly-number-iii/?show=1) | 136 | | - | [剑指 Offer II 073. 狒狒吃香蕉](https://leetcode.cn/problems/nZZqjQ/?show=1) | 137 | 138 |
139 |
140 | 141 | 142 | 143 | **_____________** 144 | 145 | 本文为会员内容,请扫码关注公众号或 [点这里](https://appktavsiei5995.pc.xiaoe-tech.com/detail/i_627cce2de4b01a4851fe0ed1/1) 查看: 146 | 147 | ![](https://labuladong.github.io/pictures/qrcode.jpg) -------------------------------------------------------------------------------- /高频面试系列/安排会议室.md: -------------------------------------------------------------------------------- 1 | # 扫描线技巧解决会议室安排问题 2 | 3 |

4 | GitHub 5 | 6 | 7 | 8 |

9 | 10 | ![](https://labuladong.github.io/pictures/souyisou1.png) 11 | 12 | **通知:[数据结构精品课](https://aep.h5.xeknow.com/s/1XJHEO) 和 [递归算法专题课](https://aep.xet.tech/s/3YGcq3) 限时附赠网站会员,全新纸质书[《labuladong 的算法笔记》](https://labuladong.gitee.io/algo/images/book/book_intro_qrcode.jpg) 出版,签名版限时半价!另外,建议你在我的 [网站](https://labuladong.github.io/algo/) 学习文章,体验更好。** 13 | 14 | 15 | 16 | 读完本文,你不仅学会了算法套路,还可以顺便解决如下题目: 17 | 18 | | LeetCode | 力扣 | 难度 | 19 | | :----: | :----: | :----: | 20 | | [253. Meeting Rooms II](https://leetcode.com/problems/meeting-rooms-ii/)🔒 | [253. 会议室 II](https://leetcode.cn/problems/meeting-rooms-ii/)🔒 | 🟠 21 | 22 | **-----------** 23 | 24 | 之前面试,被问到一道非常经典且非常实用的算法题目:会议室安排问题。 25 | 26 | 力扣上类似的问题是会员题目,你可能没办法做,但对于这种经典的算法题,掌握思路还是必要的。 27 | 28 | 先说下题目,力扣第 253 题「会议室 II」: 29 | 30 | 给你输入若干形如 `[begin, end]` 的区间,代表若干会议的开始时间和结束时间,请你计算至少需要申请多少间会议室。 31 | 32 | 函数签名如下: 33 | 34 | 35 | ```java 36 | // 返回需要申请的会议室数量 37 | int minMeetingRooms(int[][] meetings); 38 | ``` 39 | 40 | 比如给你输入 `meetings = [[0,30],[5,10],[15,20]]`,算法应该返回 2,因为后两个会议和第一个会议时间是冲突的,至少申请两个会议室才能让所有会议顺利进行。 41 | 42 | 如果会议之间的时间有重叠,那就得额外申请会议室来开会,想求至少需要多少间会议室,就是让你计算同一时刻最多有多少会议在同时进行。 43 | 44 | 换句话说,**如果把每个会议的起始时间看做一个线段区间,那么题目就是让你求最多有几个重叠区间**,仅此而已。 45 | 46 | 对于这种时间安排的问题,本质上讲就是区间调度问题,十有八九得排序,然后找规律来解决。 47 | 48 | ### 题目延伸 49 | 50 | 我们之前写过很多区间调度相关的文章,这里就顺便帮大家梳理一下这类问题的思路: 51 | 52 | 53 | 54 | 55 | 56 | **_____________** 57 | 58 | 本文为会员内容,请扫码关注公众号或 [点这里](https://appktavsiei5995.pc.xiaoe-tech.com/detail/i_649bf421e4b0f2aa7dfe0d9c/1) 查看: 59 | 60 | ![](https://labuladong.github.io/pictures/qrcode.jpg) -------------------------------------------------------------------------------- /高频面试系列/缺失和重复的元素.md: -------------------------------------------------------------------------------- 1 | # 如何寻找缺失和重复的元素 2 | 3 |

4 | GitHub 5 | 6 | 7 | 8 |

9 | 10 | ![](https://labuladong.github.io/pictures/souyisou1.png) 11 | 12 | **通知:[数据结构精品课](https://aep.h5.xeknow.com/s/1XJHEO) 和 [递归算法专题课](https://aep.xet.tech/s/3YGcq3) 限时附赠网站会员,全新纸质书[《labuladong 的算法笔记》](https://labuladong.gitee.io/algo/images/book/book_intro_qrcode.jpg) 出版,签名版限时半价!另外,建议你在我的 [网站](https://labuladong.github.io/algo/) 学习文章,体验更好。** 13 | 14 | 15 | 16 | 读完本文,你不仅学会了算法套路,还可以顺便解决如下题目: 17 | 18 | | LeetCode | 力扣 | 难度 | 19 | | :----: | :----: | :----: | 20 | | [645. Set Mismatch](https://leetcode.com/problems/set-mismatch/) | [645. 错误的集合](https://leetcode.cn/problems/set-mismatch/) | 🟢 21 | 22 | **-----------** 23 | 24 | 今天就聊一道很看起来简单却十分巧妙的问题,寻找缺失和重复的元素。之前的一篇文章 [常用的位操作](https://labuladong.github.io/article/fname.html?fname=常用的位操作) 中也写过类似的问题,不过这次的和上次的问题使用的技巧不同。 25 | 26 | 这是力扣第 645 题「错误的集合」,我来描述一下这个题目: 27 | 28 | 给一个长度为 `N` 的数组 `nums`,其中本来装着 `[1..N]` 这 `N` 个元素,无序。但是现在出现了一些错误,`nums` 中的一个元素出现了重复,也就同时导致了另一个元素的缺失。请你写一个算法,找到 `nums` 中的重复元素和缺失元素的值。 29 | 30 | 31 | ```java 32 | // 返回两个数字,分别是 {dup, missing} 33 | int[] findErrorNums(int[] nums); 34 | ``` 35 | 36 | 比如说输入:`nums = [1,2,2,4]`,算法返回 `[2,3]`。 37 | 38 | 其实很容易解决这个问题,先遍历一次数组,用一个哈希表记录每个数字出现的次数,然后遍历一次 `[1..N]`,看看那个元素重复出现,那个元素没有出现,就 OK 了。 39 | 40 | 但问题是,这个常规解法需要一个哈希表,也就是 O(N) 的空间复杂度。你看题目给的条件那么巧,在 `[1..N]` 的几个数字中恰好有一个重复,一个缺失,**事出反常必有妖**,对吧。 41 | 42 | O(N) 的时间复杂度遍历数组是无法避免的,所以我们可以想想办法如何降低空间复杂度,是否可以在 O(1) 的空间复杂度之下找到重复和缺失的元素呢? 43 | 44 | 45 | 46 | 47 |
48 |
49 | 引用本文的题目 50 | 51 | 安装 [我的 Chrome 刷题插件](https://labuladong.github.io/article/fname.html?fname=chrome插件简介) 点开下列题目可直接查看解题思路: 52 | 53 | | LeetCode | 力扣 | 54 | | :----: | :----: | 55 | | [442. Find All Duplicates in an Array](https://leetcode.com/problems/find-all-duplicates-in-an-array/?show=1) | [442. 数组中重复的数据](https://leetcode.cn/problems/find-all-duplicates-in-an-array/?show=1) | 56 | | [448. Find All Numbers Disappeared in an Array](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/?show=1) | [448. 找到所有数组中消失的数字](https://leetcode.cn/problems/find-all-numbers-disappeared-in-an-array/?show=1) | 57 | 58 |
59 |
60 | 61 | 62 | 63 | **_____________** 64 | 65 | 本文为会员内容,请扫码关注公众号或 [点这里](https://appktavsiei5995.pc.xiaoe-tech.com/detail/i_649bf4b0e4b0f2aa7dfe0e07/1) 查看: 66 | 67 | ![](https://labuladong.github.io/pictures/qrcode.jpg) 68 | 69 | ======其他语言代码====== 70 | 71 | [645.错误的集合](https://leetcode-cn.com/problems/set-mismatch) 72 | 73 | 74 | 75 | ### java 76 | 77 | [zhuli](https://github.com/1097452462 "zhuli")提供的Java代码: 78 | ```java 79 | class Solution { 80 | public int[] findErrorNums(int[] nums) { 81 | int n = nums.length; 82 | int dup = -1; 83 | for (int i = 0; i < n; i++) { 84 | // 元素是从 1 开始的 85 | int index = Math.abs(nums[i]) - 1; 86 | // nums[index] 小于 0 则说明重复访问 87 | if (nums[index] < 0) 88 | dup = Math.abs(nums[i]); 89 | else 90 | nums[index] *= -1; 91 | } 92 | int missing = -1; 93 | for (int i = 0; i < n; i++) 94 | // nums[i] 大于 0 则说明没有访问 95 | if (nums[i] > 0) 96 | // 将索引转换成元素 97 | missing = i + 1; 98 | return new int[]{dup, missing}; 99 | } 100 | } 101 | ``` 102 | 103 | 104 | 105 | ### javascript 106 | 107 | ```js 108 | /** 109 | * @param {number[]} nums 110 | * @return {number[]} 111 | */ 112 | var findErrorNums = function (nums) { 113 | let n = nums.length; 114 | let dup = -1; 115 | for (let i = 0; i < n; i++) { 116 | // 现在的元素是从1开始的 117 | let index = Math.abs(nums[i]) - 1; 118 | if (nums[index] < 0) { 119 | dup = Math.abs(nums[i]); 120 | } else { 121 | nums[index] *= -1; 122 | } 123 | } 124 | 125 | let missing = -1; 126 | for (let i = 0; i < n; i++) { 127 | if (nums[i] > 0) { 128 | // 将索引转换成元素 129 | missing = i + 1; 130 | } 131 | } 132 | 133 | return [dup, missing] 134 | }; 135 | ``` 136 | 137 | -------------------------------------------------------------------------------- /高频面试系列/随机权重.md: -------------------------------------------------------------------------------- 1 | # 带权重的随机选择算法 2 | 3 |

4 | GitHub 5 | 6 | 7 | 8 |

9 | 10 | ![](https://labuladong.github.io/pictures/souyisou1.png) 11 | 12 | **通知:[数据结构精品课](https://aep.h5.xeknow.com/s/1XJHEO) 和 [递归算法专题课](https://aep.xet.tech/s/3YGcq3) 限时附赠网站会员,全新纸质书[《labuladong 的算法笔记》](https://labuladong.gitee.io/algo/images/book/book_intro_qrcode.jpg) 出版,签名版限时半价!另外,建议你在我的 [网站](https://labuladong.github.io/algo/) 学习文章,体验更好。** 13 | 14 | 15 | 16 | 读完本文,你不仅学会了算法套路,还可以顺便解决如下题目: 17 | 18 | | LeetCode | 力扣 | 难度 | 19 | | :----: | :----: | :----: | 20 | | [528. Random Pick with Weight](https://leetcode.com/problems/random-pick-with-weight/) | [528. 按权重随机选择](https://leetcode.cn/problems/random-pick-with-weight/) | 🟠 21 | | - | [剑指 Offer II 071. 按权重生成随机数](https://leetcode.cn/problems/cuyjEf/) | 🟠 22 | 23 | **-----------** 24 | 25 | 写这篇的文章的原因是玩 LOL 手游。 26 | 27 | 我有个朋友抱怨说打排位匹配的队友太菜了,我就说我打排位觉得队友都挺行的啊,好像不怎么坑? 28 | 29 | 朋友意味深长地说了句:一般隐藏分比较高的玩家,排位如果排不到实力相当的队友,就会排到一些菜狗。 30 | 31 | 嗯?我想了几秒钟感觉这小伙子不对劲,他意思是说我隐藏分低,还是说我就是那条菜狗? 32 | 33 | 我立马要求和他开黑打一把,证明我不是菜狗,他才是菜狗。开黑结果这里不便透露,大家猜猜吧。 34 | 35 | 打完之后我就来发文了,因为我对游戏的匹配机制有了一点思考。 36 | 37 | ![](https://labuladong.github.io/pictures/随机权重/images.png) 38 | 39 | **所谓「隐藏分」我不知道是不是真的,毕竟匹配机制是所有竞技类游戏的核心环节,想必非常复杂,不是简单几个指标就能搞定的**。 40 | 41 | 但是如果把这个「隐藏分」机制简化,倒是一个值得思考的算法问题:系统如何以不同的随机概率进行匹配? 42 | 43 | 或者简单点说,如何带权重地做随机选择? 44 | 45 | 不要觉得这个很容易,如果给你一个长度为 `n` 的数组,让你从中等概率随机抽取一个元素,你肯定会做,random 一个 `[0, n-1]` 的数字出来作为索引就行了,每个元素被随机选到的概率都是 `1/n`。 46 | 47 | 但假设每个元素都有不同的权重,权重地大小代表随机选到这个元素的概率大小,你如何写算法去随机获取元素呢? 48 | 49 | 力扣第 528 题「按权重随机选择」就是这样一个问题: 50 | 51 | 52 | 53 | 我们就来思考一下这个问题,解决按照权重随机选择元素的问题。 54 | 55 | 56 | 57 |
58 |
59 | 引用本文的文章 60 | 61 | - [谈谈游戏中的随机算法](https://labuladong.github.io/article/fname.html?fname=随机算法) 62 | 63 |

64 | 65 | 66 | 67 | 68 | 69 | **_____________** 70 | 71 | 本文为会员内容,请扫码关注公众号或 [点这里](https://appktavsiei5995.pc.xiaoe-tech.com/detail/i_649bbb87e4b0b0bc2bf8e9d9/1) 查看: 72 | 73 | ![](https://labuladong.github.io/pictures/qrcode.jpg) --------------------------------------------------------------------------------