1
0
mirror of https://github.com/Snailclimb/JavaGuide synced 2025-06-20 22:17:09 +08:00

leetcode算法题推荐

This commit is contained in:
lyx 2023-10-28 18:18:37 +08:00
parent b1f22a064d
commit 59e5728e6a
2 changed files with 158 additions and 0 deletions

View File

@ -0,0 +1,109 @@
# 经典算法思想介绍
## 贪心算法
### 算法思想
贪心的本质是选择每一阶段的局部最优,从而达到全局最优。
### 一般解题步骤
- 将问题分解为若干个子问题
- 找出适合的贪心策略
- 求解每一个子问题的最优解
- 将局部最优解堆叠成全局最优解
### LeetCode
455.分发饼干https://leetcode.cn/problems/assign-cookies/
121.买卖股票的最佳时机https://leetcode.cn/problems/best-time-to-buy-and-sell-stock/
122.买卖股票的最佳时机IIhttps://leetcode.cn/problems/best-time-to-buy-and-sell-stock-ii/
55.跳跃游戏https://leetcode.cn/problems/jump-game/
45.跳跃游戏IIhttps://leetcode.cn/problems/jump-game-ii/
## 动态规划
### 算法思想
动态规划中每一个状态一定是由上一个状态推导出来的,这一点就区分于贪心,贪心没有状态推导,而是从局部直接选最优的。
经典题目01背包、完全背包
### 一般解题步骤
- 确定dp数组dp table以及下标的含义
- 确定递推公式
- dp数组如何初始化
- 确定遍历顺序
- 举例推导dp数组
### LeetCode
509.斐波那契数https://leetcode.cn/problems/fibonacci-number/
746.使用最小花费爬楼梯https://leetcode.cn/problems/min-cost-climbing-stairs/
416.分割等和子集https://leetcode.cn/problems/partition-equal-subset-sum/
518.零钱兑换https://leetcode.cn/problems/coin-change-ii/
647.回文子串https://leetcode.cn/problems/palindromic-substrings/
516.最长回文子序列https://leetcode.cn/problems/longest-palindromic-subsequence/
## 回溯算法
### 算法思想
回溯算法实际上一个类似枚举的搜索尝试过程,主要是在搜索尝试过程中寻找问题的解,当发现已不满足求解条
件时,就“回溯”返回,尝试别的路径。其本质就是穷举。
经典题目8皇后
### 一般解题步骤
- 针对所给问题,定义问题的解空间,它至少包含问题的一个(最优)解。
- 确定易于搜索的解空间结构,使得能用回溯法方便地搜索整个解空间 。
- 以深度优先的方式搜索解空间,并且在搜索过程中用剪枝函数避免无效搜索。
### leetcode
77.组合https://leetcode.cn/problems/combinations/
39.组合总和https://leetcode.cn/problems/combination-sum/
40.组合总和IIhttps://leetcode.cn/problems/combination-sum-ii/
78.子集https://leetcode.cn/problems/subsets/
90.子集IIhttps://leetcode.cn/problems/subsets-ii/
51.N皇后https://leetcode.cn/problems/n-queens/
## 分治算法
### 算法思想
将一个规模为N的问题分解为K个规模较小的子问题这些子问题相互独立且与原问题性质相同。求出子问题的解就可得到原问题的解。
经典题目:二分查找、汉诺塔问题
### 一般解题步骤
- 将原问题分解为若干个规模较小,相互独立,与原问题形式相同的子问题;
- 若子问题规模较小而容易被解决则直接解,否则递归地解各个子问题
- 将各个子问题的解合并为原问题的解。
### LeetCode
108.将有序数组转换成二叉搜索数https://leetcode.cn/problems/convert-sorted-array-to-binary-search-tree/
148.排序列表https://leetcode.cn/problems/sort-list/
23.合并k个升序链表https://leetcode.cn/problems/merge-k-sorted-lists/

View File

@ -0,0 +1,49 @@
# 数组
704.二分查找https://leetcode.cn/problems/binary-search/
80.删除有序数组中的重复项IIhttps://leetcode.cn/problems/remove-duplicates-from-sorted-array-ii
977.有序数组的平方https://leetcode.cn/problems/squares-of-a-sorted-array/
# 链表
707.设计链表https://leetcode.cn/problems/design-linked-list/
206.反转链表https://leetcode.cn/problems/reverse-linked-list/
92.反转链表IIhttps://leetcode.cn/problems/reverse-linked-list-ii/
61.旋转链表https://leetcode.cn/problems/rotate-list/
# 栈与队列
232.用栈实现队列https://leetcode.cn/problems/implement-queue-using-stacks/
225.用队列实现栈https://leetcode.cn/problems/implement-stack-using-queues/
347.前K个高频元素https://leetcode.cn/problems/top-k-frequent-elements/
239.滑动窗口最大值https://leetcode.cn/problems/sliding-window-maximum/
# 二叉树
105.从前序与中序遍历构造二叉树https://leetcode.cn/problems/construct-binary-tree-from-preorder-and-inorder-traversal/
117.填充每个节点的下一个右侧节点指针IIhttps://leetcode.cn/problems/populating-next-right-pointers-in-each-node-ii
236.二叉树的最近公共祖先https://leetcode.cn/problems/lowest-common-ancestor-of-a-binary-tree/
129.求根节点到叶节点数字之和https://leetcode.cn/problems/sum-root-to-leaf-numbers/
102.二叉树的层序遍历https://leetcode.cn/problems/binary-tree-level-order-traversal/
530.二叉搜索树的最小绝对差https://leetcode.cn/problems/minimum-absolute-difference-in-bst/
# 图
200.岛屿数量https://leetcode.cn/problems/number-of-islands/
207.课程表https://leetcode.cn/problems/course-schedule/
210.课程表IIhttps://leetcode.cn/problems/course-schedule-ii/