{"id":16536991,"url":"https://github.com/gdut-yy/leetcode-hub-java","last_synced_at":"2025-03-16T19:32:01.709Z","repository":{"id":39584429,"uuid":"382908338","full_name":"gdut-yy/leetcode-hub-java","owner":"gdut-yy","description":"基于 java21 + maven3.9 + junit5 + jacoco 的 leetcode + codeforces + atcoder + nowcoder 练习仓库。","archived":false,"fork":false,"pushed_at":"2025-03-09T12:40:08.000Z","size":34429,"stargazers_count":37,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-16T05:04:54.123Z","etag":null,"topics":["algorithm","algorithms","atcoder","codeforces","jacoco","java","java17","java21","junit5","leetcode","luogu","nowcoder","oj","oj-solutions","unit-test"],"latest_commit_sha":null,"homepage":"https://gdut-yy.github.io/doc-gitblogs-hope/module_leetcode/leetcode_trick/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gdut-yy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-04T17:16:32.000Z","updated_at":"2025-03-09T12:40:12.000Z","dependencies_parsed_at":"2025-03-02T15:33:28.494Z","dependency_job_id":null,"html_url":"https://github.com/gdut-yy/leetcode-hub-java","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gdut-yy%2Fleetcode-hub-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gdut-yy%2Fleetcode-hub-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gdut-yy%2Fleetcode-hub-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gdut-yy%2Fleetcode-hub-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gdut-yy","download_url":"https://codeload.github.com/gdut-yy/leetcode-hub-java/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243920088,"owners_count":20368993,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","algorithms","atcoder","codeforces","jacoco","java","java17","java21","junit5","leetcode","luogu","nowcoder","oj","oj-solutions","unit-test"],"created_at":"2024-10-11T18:34:21.033Z","updated_at":"2025-03-16T19:31:56.698Z","avatar_url":"https://github.com/gdut-yy.png","language":"Java","readme":"# algo-hub-java\n\n基于 `jdk21` + `maven3.9` + `junit5` + `jacoco` 的 leetcode + codeforces + atcoder + nowcoder 练习仓库。\n\n`@since` 2021.07.05\n\n~~（拼搏百天，我要完成 300 道 leetcode 题！（Day87 (2021.09.29) 已完成 303 题）~~\n\n~~（拼搏 300 天，我要完成 1000 道 leetcode 题！（Day269 (2022.03.30) 已完成 1001 题）~~\n\n~~（Day545 (2022.12.31) 已完成 1665 题）~~\n\nDay911 (2024.01.01) 已完成：\n\n- leetcode: 2251 题\n- codeforces: 559 题\n- atcoder: 290 题\n\n---\n\n- `atcoder-*` 存放 atcoder 题目。\n- `codeforces-*` 存放 codeforces 题目。\n- `leetcode-n` 存放 `100 * (n - 1) + 1` ~ `100 * n` 的题目（如 `leetcode-19` 存放 `1801` ~ `1900` 的题目）。\n- `leetcode-core` 存放 leetcode 自定义对象。\n- `leetcode-extends` 存放 专场竞赛/OJ 题目\n- `leetcode-interview` 存放 《程序员面试金典》 题目。\n- `leetcode-lcp` 存放 力扣杯 题目。\n- `leetcode-offer` 存放 《剑指 Offer》 题目。\n- `nowcoder-*` 存放 牛客 题目。\n- `数据库` 题目存放于 [https://gitee.com/gdut_yy/leetcode-hub-mysql](https://gitee.com/gdut_yy/leetcode-hub-mysql)\n\n## 环境信息\n\n```sh\n$ java -version\nopenjdk 21 2023-09-19\nOpenJDK Runtime Environment (build 21+35-2513)\nOpenJDK 64-Bit Server VM (build 21+35-2513, mixed mode, sharing)\n\n$ mvn -v\nApache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937)\nMaven home: D:\\programs\\apache-maven-3.9.9\nJava version: 21, vendor: Oracle Corporation, runtime: D:\\programs\\jdk-21\nDefault locale: zh_CN, platform encoding: UTF-8\nOS name: \"windows 11\", version: \"10.0\", arch: \"amd64\", family: \"windows\"\n\nIntelliJ IDEA 2024.2.2 (Community Edition)\nBuild #IC-242.22855.74, built on September 18, 2024\n```\n\n## Command 命令行\n\n```sh\n# 运行 UT、统计覆盖率（jdk21）：\nmvn clean verify -s settings.xml\n\n# 统计做题进度（python3）：\npython countSolutions.py\n```\n\n![](./README/ut-coverage-report-2023.png)\n\n## UT、TDD\n\njava 项目中常见的测试框架：\n\n- [junit4](https://github.com/junit-team/junit4)\n- [junit5](https://github.com/junit-team/junit5)\n- [testng](https://github.com/cbeust/testng)\n- [jmh](https://github.com/openjdk/jmh)\n- [jacoco](https://github.com/jacoco/jacoco)\n\nmock 框架：\n\n- [easymock](https://github.com/easymock/easymock)\n- [mockito](https://github.com/mockito/mockito)\n- [powermock](https://github.com/powermock/powermock)\n\njunit5 常用断言：\n\n- Assertions.assertEquals\n- Assertions.assertTrue\n- Assertions.assertFalse\n- Assertions.assertArrayEquals\n\n思考：一些较为特殊的判题 UT 写法：\n\n1. 部分题目使用了自定义对象（链表、二叉树等），`Assertions.assertEquals` 不能满足这种场景，可使用自定义断言对这类对象进行判等：\n   - `ListNode` 可参考 `ListNode#assertListNodeEquals(ListNode expected, ListNode actual)`，如第 2、19、21、23、82 题等；\n   - `TreeNode` 可参考 `TreeNode#assertTreeNodeEquals(TreeNode expected, TreeNode actual)`，如第 105、114、156、226、235 题等；\n   - 不失一般性地，其他自定义对象可参考 `UtUtils#assertJsonEquals(Object expected, Object actual)`，如第 138、430、708 题等；\n2. 部分题目符合题意的答案并不止一个，可以构造一个 `List\u003cT\u003e expectedList` 去判断是否 `contains()` 如第 5、162 题等；\n3. 部分题目符合题意的答案是一个集合，但对集合元素的顺序没有要求，可以对 `expected` 和 `actual` 集合进行排序后判等：\n   - `List\u003cList\u003cInteger\u003e\u003e` 可参考 `UtUtils#INTEGER_LIST_COMPARATOR`，如第 18、39、40、46、47 题等；\n   - `List\u003cList\u003cString\u003e\u003e` 可参考 `UtUtils#STRING_LIST_COMPARATOR`，如第 49、51 题等；\n4. 部分题目是非精确判等（随机问题），如第 384、528 题等；\n\n---\n\n一些心得：\n\n1. leetcode 题目，可从 `F12` 控制台 `Request Payload` 中 `mySubmissionDetail` 关键词抓取；\n2. 使用 Java 反射实现 UT 的题目：716、2227、2276、2286；\n3. 类中提供接口，UT 中需实现该接口：341、489、702、1095、1428、1533；\n\n## 一些 Trick\n\n```java\n  // 数组 使用 Map\u003cInteger, Integer\u003e 统计每个数值出现的频次\n  int[] nums = {4, 1, 2, 1, 2};\n  Map\u003cInteger, Integer\u003e cntMap = new HashMap\u003c\u003e();\n  for (int num : nums) {\n      // Verbose\n      if (!cntMap.containsKey(num)) {\n          cntMap.put(num, 0);\n      }\n      cntMap.put(num, cntMap.get(num) + 1);\n      // Obvious\n      cntMap.put(num, cntMap.getOrDefault(num, 0) + 1);\n  }\n```\n\n```java\n  // 有向图 使用 Map\u003cInteger, List\u003cInteger\u003e\u003e 建图\n  int[][] edges = {{0, 1}, {0, 2}, {0, 3}, {1, 4}};\n  Map\u003cInteger, List\u003cInteger\u003e\u003e adj = new HashMap\u003c\u003e();\n  for (int[] edge : edges) {\n      int u = edge[0];\n      int v = edge[1];\n      // Verbose\n      if (!adj.containsKey(u)) {\n          adj.put(u, new ArrayList\u003c\u003e());\n      }\n      adj.get(u).add(v);\n      // Obvious\n      adj.computeIfAbsent(u, key -\u003e new ArrayList\u003c\u003e()).add(v);\n  }\n```\n\n## 常用算法模板\n\n### 打表\n\n[预计算结果](https://support.leetcode-cn.com/hc/kb/article/1278066)\n\n预计算结果是指：用户预先计算了部分或全部测试用例结果，并将其直接添加到至提交代码中。\n\n规则及判分方式：如果参赛者的提交代码存在预计算结果的行为，我们建议参赛者附上生成预计算结果的代码。如参赛者含预计算结果的代码 “AC” 了题目，力扣将判定参赛者的提交为有效提交。\n\n- [231. 2 的幂](https://leetcode.cn/problems/power-of-two/)\n- [326. 3 的幂](https://leetcode.cn/problems/power-of-three/)\n- [342. 4 的幂](https://leetcode.cn/problems/power-of-four/)\n- [866. 回文素数](https://leetcode.cn/problems/prime-palindrome/)\n- [906. 超级回文数](https://leetcode.cn/problems/super-palindromes/)\n- [1969. 数组元素的最小非零乘积](https://leetcode.cn/problems/minimum-non-zero-product-of-the-array-elements/)\n- [2048. 下一个更大的数值平衡数](https://leetcode.cn/problems/next-greater-numerically-balanced-number/)\n\n### 线段树\n\n- [2286. 以组为单位订音乐会的门票](https://leetcode.cn/problems/booking-concert-tickets-in-groups/) 单点修改、区间求和、二分最小满足下标\n\n### 快速幂\n\n[模板代码](./leetcode-core/src/main/java/template/QuickPower.java)\n\n- [1922. 统计好数字的数目](https://leetcode.cn/problems/count-good-numbers/)\n- [1969. 数组元素的最小非零乘积](https://leetcode.cn/problems/minimum-non-zero-product-of-the-array-elements/)\n\n### 双指针\n\n快慢指针\n\n- [19. 删除链表的倒数第 N 个结点](https://leetcode.cn/problems/remove-nth-node-from-end-of-list/)\n- [26. 删除有序数组中的重复项](https://leetcode.cn/problems/remove-duplicates-from-sorted-array/)\n- [27. 移除元素](https://leetcode.cn/problems/remove-element/)\n- [83. 删除排序链表中的重复元素](https://leetcode.cn/problems/remove-duplicates-from-sorted-list/)\n- [141. 环形链表](https://leetcode.cn/problems/linked-list-cycle/)\n- [142. 环形链表 II](https://leetcode.cn/problems/linked-list-cycle-ii/)\n- [283. 移动零](https://leetcode.cn/problems/move-zeroes/)\n- [876. 链表的中间结点](https://leetcode.cn/problems/middle-of-the-linked-list/)\n\n### 买卖股票系列\n\n- [121. 买卖股票的最佳时机](https://leetcode.cn/problems/best-time-to-buy-and-sell-stock/solution/) 暴力解法、动态规划（Java）\n- [122. 买卖股票的最佳时机 II](https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-ii/) 暴力搜索、贪心算法、动态规划（Java）\n- [123. 买卖股票的最佳时机 III](https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-iii/) 动态规划（Java）\n- [188. 买卖股票的最佳时机 IV](https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-iv) 动态规划（「力扣」更新过用例，只有优化空间的版本可以 AC）\n- [309. 最佳买卖股票时机含冷冻期](https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-with-cooldown) 动态规划（Java）\n- [714. 买卖股票的最佳时机含手续费](https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-with-transaction-fee) 动态规划（Java）\n\n### 打家劫舍系列\n\n- [198. 打家劫舍](https://leetcode.cn/problems/house-robber/)\n- [213. 打家劫舍 II](https://leetcode.cn/problems/house-robber-ii/)\n\n### 存在重复元素系列\n\n- [217. 存在重复元素](https://leetcode.cn/problems/contains-duplicate/)\n- [219. 存在重复元素 II](https://leetcode.cn/problems/contains-duplicate-ii/)\n- [220. 存在重复元素 III](https://leetcode.cn/problems/contains-duplicate-iii/)\n\n### 最大连续 1 的个数\n\n- [485. 最大连续 1 的个数](https://leetcode.cn/problems/max-consecutive-ones/)\n- [$487. 最大连续 1 的个数 II](https://leetcode.cn/problems/max-consecutive-ones-ii/)\n- [1004. 最大连续 1 的个数 III](https://leetcode.cn/problems/max-consecutive-ones-iii/)\n\n### Manacher 马拉车算法\n\n- [5. 最长回文子串](https://leetcode.cn/problems/longest-palindromic-substring/)\n- [1960. 两个回文子字符串长度的最大乘积](https://leetcode.cn/problems/maximum-product-of-the-length-of-two-palindromic-substrings/)\n\n### 数制转换\n\n- [12. 整数转罗马数字](https://leetcode.cn/problems/integer-to-roman/)\n- [13. 罗马数字转整数](https://leetcode.cn/problems/roman-to-integer/)\n- [504. 七进制数](https://leetcode.cn/problems/base-7/)\n\n### 螺旋矩阵\n\n- [54. 螺旋矩阵](https://leetcode.cn/problems/spiral-matrix/)\n- [59. 螺旋矩阵 II](https://leetcode.cn/problems/spiral-matrix-ii/)\n- [885. 螺旋矩阵 III](https://leetcode.cn/problems/spiral-matrix-iii/)\n\n### 二叉树\n\n二叉树前序遍历 (preorder)、中序遍历 (inorder)、后序遍历 (postorder)\n\n- [144. 二叉树的前序遍历](https://leetcode.cn/problems/binary-tree-preorder-traversal/)\n- [94. 二叉树的中序遍历](https://leetcode.cn/problems/binary-tree-inorder-traversal/)\n- [145. 二叉树的后序遍历](https://leetcode.cn/problems/binary-tree-postorder-traversal/)\n\n扩展到 N 叉树（N 叉树没有 中序遍历）\n\n- [589. N 叉树的前序遍历](https://leetcode.cn/problems/n-ary-tree-preorder-traversal/)\n- [590. N 叉树的后序遍历](https://leetcode.cn/problems/n-ary-tree-postorder-traversal/)\n\n二叉树层序遍历\n\n- [102. 二叉树的层序遍历](https://leetcode.cn/problems/binary-tree-level-order-traversal/)\n- [107. 二叉树的层序遍历 II](https://leetcode.cn/problems/binary-tree-level-order-traversal-ii/)\n- [103. 二叉树的锯齿形层序遍历](https://leetcode.cn/problems/binary-tree-zigzag-level-order-traversal/)\n- [104. 二叉树的最大深度](https://leetcode.cn/problems/maximum-depth-of-binary-tree/)\n- [111. 二叉树的最小深度](https://leetcode.cn/problems/minimum-depth-of-binary-tree/)\n- [637. 二叉树的层平均值](https://leetcode.cn/problems/average-of-levels-in-binary-tree/)\n\n```java\npublic List\u003cList\u003cInteger\u003e\u003e levelOrder(TreeNode root) {\n    List\u003cList\u003cInteger\u003e\u003e resList = new ArrayList\u003c\u003e();\n    if (root == null) {\n        return resList;\n    }\n    Queue\u003cTreeNode\u003e queue = new LinkedList\u003c\u003e();\n    queue.add(root);\n    while (!queue.isEmpty()) {\n        List\u003cInteger\u003e curLevel = new ArrayList\u003c\u003e();\n        int size = queue.size();\n        for (int i = 0; i \u003c size; i++) {\n            // 上下文已保证 cur 不为 null\n            TreeNode cur = queue.remove();\n            curLevel.add(cur.val);\n            if (cur.left != null) {\n                queue.add(cur.left);\n            }\n            if (cur.right != null) {\n                queue.add(cur.right);\n            }\n        }\n        resList.add(curLevel);\n    }\n    return resList;\n}\n```\n\n二叉树序列化\n\n- [297. 二叉树的序列化与反序列化](https://leetcode.cn/problems/serialize-and-deserialize-binary-tree/)\n- [449. 序列化和反序列化二叉搜索树](https://leetcode.cn/problems/serialize-and-deserialize-bst/)\n\n其他\n\n- [100. 相同的树](https://leetcode.cn/problems/same-tree/)\n- [114. 二叉树展开为链表](https://leetcode.cn/problems/flatten-binary-tree-to-linked-list/)\n- [116. 填充每个节点的下一个右侧节点指针](https://leetcode.cn/problems/populating-next-right-pointers-in-each-node/)\n- [226. 翻转二叉树](https://leetcode.cn/problems/invert-binary-tree/)\n\n### 单调栈\n\n注意：Java 中 \"栈\" 应使用 Deque 代替 Stack（Java 官方建议）。即：\n\n```java\n// Bad\nStack\u003cT\u003e stack = new Stack\u003c\u003e();\n\n// Good\nDeque\u003cT\u003e stack = new ArrayDeque\u003c\u003e();\n```\n\n注意二者转 stream 时的顺序：\n\n```java\nStack\u003cInteger\u003e stack1 = new Stack\u003c\u003e();\nDeque\u003cInteger\u003e stack2 = new ArrayDeque\u003c\u003e();\nstack1.push(1); stack1.push(2); stack1.push(3);\nstack2.push(1); stack2.push(2); stack2.push(3);\nSystem.out.println(Arrays.toString(stack1.stream().mapToInt(i -\u003e i).toArray())); // [1, 2, 3]\nSystem.out.println(Arrays.toString(stack2.stream().mapToInt(i -\u003e i).toArray())); // [3, 2, 1]\n```\n\n- [496. 下一个更大元素 I](https://leetcode.cn/problems/next-greater-element-i/)\n- [503. 下一个更大元素 II](https://leetcode.cn/problems/next-greater-element-ii/)\n- [739. 每日温度](https://leetcode.cn/problems/daily-temperatures/)\n- [1944. 队列中可以看到的人数](https://leetcode.cn/problems/number-of-visible-people-in-a-queue/)\n\n### 状态压缩 DP\n\n- [78. 子集](https://leetcode.cn/problems/subsets/)\n- [90. 子集 II](https://leetcode.cn/problems/subsets-ii/)\n- [1049. 最后一块石头的重量 II](https://leetcode.cn/problems/last-stone-weight-ii/)\n- [1755. 最接近目标值的子序列和](https://leetcode.cn/problems/closest-subsequence-sum/)\n- [2035. 将数组分成两个数组并最小化数组和的差](https://leetcode.cn/problems/partition-array-into-two-arrays-to-minimize-sum-difference/)\n\n### 只出现一次的数字系列\n\n1. [136. 只出现一次的数字](https://leetcode.cn/problems/single-number/)\n2. [137. 只出现一次的数字 II](https://leetcode.cn/problems/single-number-ii/)\n3. [260. 只出现一次的数字 III](https://leetcode.cn/problems/single-number-iii/)\n\n```java\n// 给定一个非空整数数组，除了某个元素只出现一次以外，其余每个元素均出现两次。找出那个只出现了一次的元素。\npublic int singleNumber(int[] nums) {\n    int single = 0;\n    for (int num : nums) {\n        single ^= num;\n    }\n    return single;\n}\n\n// 给你一个整数数组 nums ，除某个元素仅出现 一次 外，其余每个元素都恰出现 三次 。请你找出并返回那个只出现了一次的元素。\npublic int singleNumber2(int[] nums) {\n    int a = 0;\n    int b = 0;\n    for (int num : nums) {\n        b = ~a \u0026 (b ^ num);\n        a = ~b \u0026 (a ^ num);\n    }\n    return b;\n}\n\n// 给定一个整数数组 nums，其中恰好有两个元素只出现一次，其余所有元素均出现两次。找出只出现一次的那两个元素。你可以按 任意顺序 返回答案。\npublic int[] singleNumber2(int[] nums) {\n    int xorsum = 0;\n    for (int num : nums) {\n        xorsum ^= num;\n    }\n    // 防止溢出\n    int lsb = (xorsum == Integer.MIN_VALUE ? xorsum : xorsum \u0026 (-xorsum));\n    int type1 = 0;\n    int type2 = 0;\n    for (int num : nums) {\n        if ((num \u0026 lsb) != 0) {\n            type1 ^= num;\n        } else {\n            type2 ^= num;\n        }\n    }\n    return new int[]{type1, type2};\n}\n```\n\n### 石子游戏系列\n\n- [877. 石子游戏](https://leetcode.cn/problems/stone-game/)\n- [1140. 石子游戏 II](https://leetcode.cn/problems/stone-game-ii/)\n- [1406. 石子游戏 III](https://leetcode.cn/problems/stone-game-iii/)\n- [1510. 石子游戏 IV](https://leetcode.cn/problems/stone-game-iv/)\n- [1563. 石子游戏 V](https://leetcode.cn/problems/stone-game-v/)\n- [1686. 石子游戏 VI](https://leetcode.cn/problems/stone-game-vi/)\n- [1690. 石子游戏 VII](https://leetcode.cn/problems/stone-game-vii/)\n- [1872. 石子游戏 VIII](https://leetcode.cn/problems/stone-game-viii/)\n- [2029. 石子游戏 IX](https://leetcode.cn/problems/stone-game-ix/)\n\n### 图论\n\n- 顶点 Vertex (复数 vertices)\n- 边 Edge\n- 有向图 directed graph\n- 无向图 undirected graph\n- 有向无环图 DAG (Directed Acyclic Graph)\n- 入度 indegree\n- 出度 outdegree\n\n### 拓扑排序 (Topological Sort)\n\n每次将入度为 0 的顶点加入队列。\n\n- [207. 课程表](https://leetcode.cn/problems/course-schedule/)\n- [210. 课程表 II](https://leetcode.cn/problems/course-schedule-ii/)\n- [$269. 火星词典](https://leetcode.cn/problems/alien-dictionary/) [困难]\n- [$444. 序列重建](https://leetcode.cn/problems/sequence-reconstruction/)\n- [1136. 平行课程](https://leetcode.cn/problems/parallel-courses/)\n- [2050. 并行课程 III](https://leetcode.cn/problems/parallel-courses-iii/) [困难]\n\n### 并查集 (UnionFind)\n\n[模板代码](./leetcode-core/src/main/java/template/UnionFind.java)\n\n- [200. 岛屿数量](https://leetcode.cn/problems/number-of-islands/)\n- [$323. 无向图中连通分量的数目](https://leetcode.cn/problems/number-of-connected-components-in-an-undirected-graph/)\n- [547. 省份数量](https://leetcode.cn/problems/number-of-provinces/)\n- [684. 冗余连接](https://leetcode.cn/problems/redundant-connection/)\n- [765. 情侣牵手](https://leetcode.cn/problems/couples-holding-hands/) [困难]\n- [839. 相似字符串组](https://leetcode.cn/problems/similar-string-groups/)\n- [990. 等式方程的可满足性](https://leetcode.cn/problems/satisfiability-of-equality-equations/)\n- [1319. 连通网络的操作次数](https://leetcode.cn/problems/number-of-operations-to-make-network-connected/)\n- [1992. 找到所有的农场组](https://leetcode.cn/problems/find-all-groups-of-farmland/)\n- [2076. 处理含限制条件的好友请求](https://leetcode.cn/problems/process-restricted-friend-requests/) [困难]\n\n### 最短路 (Shortest Path)\n\n- Floyd 求任意两个结点之间的最短路。 时间复杂度 O(n^3)\n- Dijkstra 求解 非负权图 上单源最短路径的算法。时间复杂度 O(n^2) / O(mlogn)\n- Bellman ford 可以求出有负权的图的最短路 时间复杂度 O(mn)\n\n---\n\n- [743. 网络延迟时间](https://leetcode.cn/problems/network-delay-time/)\n- [1368. 使网格图至少有一条有效路径的最小代价](https://leetcode.cn/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid/)\n- [1514. 概率最大的路径](https://leetcode.cn/problems/path-with-maximum-probability/)\n\n### 欧拉回路 (Eulerian Circuit)\n\nHierholzer 算法\n\n- [332. 重新安排行程](https://leetcode.cn/problems/reconstruct-itinerary/)\n\n### 二分图最大权匹配\n\n二部图 Bipartite Graph\n\n匈牙利算法（KM 算法）\n\n- [1066. 校园自行车分配 II](https://leetcode.cn/problems/campus-bikes-ii/)\n- [1947. 最大兼容性评分和](https://leetcode.cn/problems/maximum-compatibility-score-sum/)\n\n### 最小生成树 (Minimum Spanning Trees)\n\n- Prim（普里姆）算法\n- Kruskal（克鲁斯卡尔）算法 边优先 O(mlogm) m 条边\n\n---\n\n- [$1135. 最低成本联通所有城市](https://leetcode.cn/problems/connecting-cities-with-minimum-cost/)\n- [$1168. 水资源分配优化](https://leetcode.cn/problems/optimize-water-distribution-in-a-village/)\n- [1489. 找到最小生成树里的关键边和伪关键边](https://leetcode.cn/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/)\n- [1584. 连接所有点的最小费用](https://leetcode.cn/problems/min-cost-to-connect-all-points/)\n\n### 网络流问题 (Network Flow Problems)\n\n- Ford-Fulkerson 算法（最坏情况时间复杂度 O(f\\*m) f 为最大流大小 m 为边的数量）\n- Edmonds-Karp 算法 最短路 时间复杂度 O(n\\*m^2) n 为顶点数量 m 为边数量\n- Dinic 算法 时间复杂度 O(m\\*n^2) level graph\n\n## 学习资源\n\n- [OI-Wiki](https://oi-wiki.org/)\n- [codeforces](https://codeforces.com/)\n- [atcoder](https://atcoder.jp/home)\n- [acwing](https://www.acwing.com/)\n- [北大 OJ](http://poj.org/)\n- [中科大 OJ](http://acm.ustc.edu.cn/ustcoj/)\n- ~~[杭电 OJ](https://www.acm.hdu.edu.cn/)~~\n- ~~[哈工大 OJ](http://acm.hit.edu.cn/)~~\n- [洛谷](https://www.luogu.com.cn/)\n- [excalidraw](https://excalidraw.com/)\n- ~~[leetcode-rating-predictor](https://lcpredictor.onrender.com/) | [github](https://github.com/SysSn13/leetcode-rating-predictor)~~\n- [lccn.lbao.site](https://lccn.lbao.site/)\n- [zerotrac-leetcode_problem_rating](https://zerotrac.github.io/leetcode_problem_rating/)\n- [clist.by](https://clist.by/account/zhang-yi-yang/resource/leetcode.com/)\n- [visualgo](https://visualgo.net/zh)\n- [宫水三叶の刷题日记](https://www.acoier.com/tags/)\n- [灵茶の试炼](https://docs.qq.com/sheet/DWGFoRGVZRmxNaXFz?tab=BB08J2)\n\n（全文完）\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgdut-yy%2Fleetcode-hub-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgdut-yy%2Fleetcode-hub-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgdut-yy%2Fleetcode-hub-java/lists"}