|
1 |
| -# algo-hub-java |
| 1 | +# algo-hub-java-cpp |
2 | 2 |
|
3 |
| -基于 `jdk21` + `maven3.9` + `junit5` + `jacoco` 的 leetcode + codeforces + atcoder + nowcoder 练习仓库。 |
| 3 | +基于 `jdk21` + `junit5` + `jacoco` 的 leetcode + codeforces + atcoder + nowcoder + luogu 练习仓库。 |
4 | 4 |
|
5 |
| -`@since` 2021.07.05 |
| 5 | +`@since` 2021.07.05,Day 1413 (2025.05.17) 已收录: |
6 | 6 |
|
7 |
| -~~(拼搏百天,我要完成 300 道 leetcode 题!(Day87 (2021.09.29) 已完成 303 题)~~ |
8 |
| - |
9 |
| -~~(拼搏 300 天,我要完成 1000 道 leetcode 题!(Day269 (2022.03.30) 已完成 1001 题)~~ |
10 |
| - |
11 |
| -~~(Day545 (2022.12.31) 已完成 1665 题)~~ |
12 |
| - |
13 |
| -Day911 (2024.01.01) 已完成: |
14 |
| - |
15 |
| -- leetcode: 2251 题 |
16 |
| -- codeforces: 559 题 |
17 |
| -- atcoder: 290 题 |
| 7 | +- leetcode: 3195 题 |
| 8 | +- codeforces: 1021 题 |
| 9 | +- atcoder: 345 题 |
18 | 10 |
|
19 | 11 | ---
|
20 | 12 |
|
21 |
| -- `atcoder-*` 存放 atcoder 题目。 |
22 |
| -- `codeforces-*` 存放 codeforces 题目。 |
23 | 13 | - `leetcode-n` 存放 `100 * (n - 1) + 1` ~ `100 * n` 的题目(如 `leetcode-19` 存放 `1801` ~ `1900` 的题目)。
|
24 |
| -- `leetcode-core` 存放 leetcode 自定义对象。 |
25 | 14 | - `leetcode-extends` 存放 专场竞赛/OJ 题目
|
26 | 15 | - `leetcode-interview` 存放 《程序员面试金典》 题目。
|
27 | 16 | - `leetcode-lcp` 存放 力扣杯 题目。
|
28 | 17 | - `leetcode-offer` 存放 《剑指 Offer》 题目。
|
29 |
| -- `nowcoder-*` 存放 牛客 题目。 |
30 | 18 | - `数据库` 题目存放于 [https://gitee.com/gdut_yy/leetcode-hub-mysql](https://gitee.com/gdut_yy/leetcode-hub-mysql)
|
31 | 19 |
|
32 | 20 | ## 环境信息
|
@@ -58,8 +46,6 @@ mvn clean verify -s settings.xml
|
58 | 46 | python countSolutions.py
|
59 | 47 | ```
|
60 | 48 |
|
61 |
| - |
62 |
| - |
63 | 49 | ## UT、TDD
|
64 | 50 |
|
65 | 51 | java 项目中常见的测试框架:
|
@@ -103,42 +89,10 @@ junit5 常用断言:
|
103 | 89 | 2. 使用 Java 反射实现 UT 的题目:716、2227、2276、2286;
|
104 | 90 | 3. 类中提供接口,UT 中需实现该接口:341、489、702、1095、1428、1533;
|
105 | 91 |
|
106 |
| -## 一些 Trick |
107 |
| - |
108 |
| -```java |
109 |
| - // 数组 使用 Map<Integer, Integer> 统计每个数值出现的频次 |
110 |
| - int[] nums = {4, 1, 2, 1, 2}; |
111 |
| - Map<Integer, Integer> cntMap = new HashMap<>(); |
112 |
| - for (int num : nums) { |
113 |
| - // Verbose |
114 |
| - if (!cntMap.containsKey(num)) { |
115 |
| - cntMap.put(num, 0); |
116 |
| - } |
117 |
| - cntMap.put(num, cntMap.get(num) + 1); |
118 |
| - // Obvious |
119 |
| - cntMap.put(num, cntMap.getOrDefault(num, 0) + 1); |
120 |
| - } |
121 |
| -``` |
122 |
| - |
123 |
| -```java |
124 |
| - // 有向图 使用 Map<Integer, List<Integer>> 建图 |
125 |
| - int[][] edges = {{0, 1}, {0, 2}, {0, 3}, {1, 4}}; |
126 |
| - Map<Integer, List<Integer>> adj = new HashMap<>(); |
127 |
| - for (int[] edge : edges) { |
128 |
| - int u = edge[0]; |
129 |
| - int v = edge[1]; |
130 |
| - // Verbose |
131 |
| - if (!adj.containsKey(u)) { |
132 |
| - adj.put(u, new ArrayList<>()); |
133 |
| - } |
134 |
| - adj.get(u).add(v); |
135 |
| - // Obvious |
136 |
| - adj.computeIfAbsent(u, key -> new ArrayList<>()).add(v); |
137 |
| - } |
138 |
| -``` |
139 |
| - |
140 | 92 | ## 常用算法模板
|
141 | 93 |
|
| 94 | +- [一个方法团灭 LeetCode 打家劫舍问题](https://gdut-yy.github.io/doc-gitblogs-hope/module_algo/dp/state-machine/) |
| 95 | + |
142 | 96 | ### 打表
|
143 | 97 |
|
144 | 98 | [预计算结果](https://support.leetcode-cn.com/hc/kb/article/1278066)
|
@@ -179,20 +133,6 @@ junit5 常用断言:
|
179 | 133 | - [283. 移动零](https://leetcode.cn/problems/move-zeroes/)
|
180 | 134 | - [876. 链表的中间结点](https://leetcode.cn/problems/middle-of-the-linked-list/)
|
181 | 135 |
|
182 |
| -### 买卖股票系列 |
183 |
| - |
184 |
| -- [121. 买卖股票的最佳时机](https://leetcode.cn/problems/best-time-to-buy-and-sell-stock/solution/) 暴力解法、动态规划(Java) |
185 |
| -- [122. 买卖股票的最佳时机 II](https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-ii/) 暴力搜索、贪心算法、动态规划(Java) |
186 |
| -- [123. 买卖股票的最佳时机 III](https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-iii/) 动态规划(Java) |
187 |
| -- [188. 买卖股票的最佳时机 IV](https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-iv) 动态规划(「力扣」更新过用例,只有优化空间的版本可以 AC) |
188 |
| -- [309. 最佳买卖股票时机含冷冻期](https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-with-cooldown) 动态规划(Java) |
189 |
| -- [714. 买卖股票的最佳时机含手续费](https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-with-transaction-fee) 动态规划(Java) |
190 |
| - |
191 |
| -### 打家劫舍系列 |
192 |
| - |
193 |
| -- [198. 打家劫舍](https://leetcode.cn/problems/house-robber/) |
194 |
| -- [213. 打家劫舍 II](https://leetcode.cn/problems/house-robber-ii/) |
195 |
| - |
196 | 136 | ### 存在重复元素系列
|
197 | 137 |
|
198 | 138 | - [217. 存在重复元素](https://leetcode.cn/problems/contains-duplicate/)
|
@@ -244,34 +184,6 @@ junit5 常用断言:
|
244 | 184 | - [111. 二叉树的最小深度](https://leetcode.cn/problems/minimum-depth-of-binary-tree/)
|
245 | 185 | - [637. 二叉树的层平均值](https://leetcode.cn/problems/average-of-levels-in-binary-tree/)
|
246 | 186 |
|
247 |
| -```java |
248 |
| -public List<List<Integer>> levelOrder(TreeNode root) { |
249 |
| - List<List<Integer>> resList = new ArrayList<>(); |
250 |
| - if (root == null) { |
251 |
| - return resList; |
252 |
| - } |
253 |
| - Queue<TreeNode> queue = new LinkedList<>(); |
254 |
| - queue.add(root); |
255 |
| - while (!queue.isEmpty()) { |
256 |
| - List<Integer> curLevel = new ArrayList<>(); |
257 |
| - int size = queue.size(); |
258 |
| - for (int i = 0; i < size; i++) { |
259 |
| - // 上下文已保证 cur 不为 null |
260 |
| - TreeNode cur = queue.remove(); |
261 |
| - curLevel.add(cur.val); |
262 |
| - if (cur.left != null) { |
263 |
| - queue.add(cur.left); |
264 |
| - } |
265 |
| - if (cur.right != null) { |
266 |
| - queue.add(cur.right); |
267 |
| - } |
268 |
| - } |
269 |
| - resList.add(curLevel); |
270 |
| - } |
271 |
| - return resList; |
272 |
| -} |
273 |
| -``` |
274 |
| - |
275 | 187 | 二叉树序列化
|
276 | 188 |
|
277 | 189 | - [297. 二叉树的序列化与反序列化](https://leetcode.cn/problems/serialize-and-deserialize-binary-tree/)
|
@@ -481,4 +393,5 @@ Hierholzer 算法
|
481 | 393 | - [宫水三叶の刷题日记](https://www.acoier.com/tags/)
|
482 | 394 | - [灵茶の试炼](https://docs.qq.com/sheet/DWGFoRGVZRmxNaXFz?tab=BB08J2)
|
483 | 395 |
|
484 |
| -(全文完) |
| 396 | +[](https://leetcode.cn/u/ning2ing/) |
| 397 | +[](https://codeforces.com/profile/ning1ing) |
0 commit comments