diff --git a/Contents/00.Introduction/04.Solutions-List.md b/Contents/00.Introduction/04.Solutions-List.md index 1a478b65..5ff9b672 100644 --- a/Contents/00.Introduction/04.Solutions-List.md +++ b/Contents/00.Introduction/04.Solutions-List.md @@ -1,4 +1,4 @@ -# LeetCode 题解(已完成 712 道) +# LeetCode 题解(已完成 715 道) | 题号 | 标题 | 题解 | 标签 | 难度 | | :------ | :------ | :------ | :------ | :------ | @@ -24,6 +24,7 @@ | 0022 | [括号生成](https://leetcode.cn/problems/generate-parentheses/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0022.%20%E6%8B%AC%E5%8F%B7%E7%94%9F%E6%88%90.md) | 字符串、回溯算法 | 中等 | | 0023 | [合并K个升序链表](https://leetcode.cn/problems/merge-k-sorted-lists/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0023.%20%E5%90%88%E5%B9%B6K%E4%B8%AA%E5%8D%87%E5%BA%8F%E9%93%BE%E8%A1%A8.md) | 链表、分治、堆(优先队列)、归并排序 | 困难 | | 0024 | [两两交换链表中的节点](https://leetcode.cn/problems/swap-nodes-in-pairs/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0024.%20%E4%B8%A4%E4%B8%A4%E4%BA%A4%E6%8D%A2%E9%93%BE%E8%A1%A8%E4%B8%AD%E7%9A%84%E8%8A%82%E7%82%B9.md) | 递归、链表 | 中等 | +| 0025 | [K 个一组翻转链表](https://leetcode.cn/problems/reverse-nodes-in-k-group/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0025.%20K%20%E4%B8%AA%E4%B8%80%E7%BB%84%E7%BF%BB%E8%BD%AC%E9%93%BE%E8%A1%A8.md) | 递归、链表 | 困难 | | 0026 | [删除有序数组中的重复项](https://leetcode.cn/problems/remove-duplicates-from-sorted-array/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0026.%20%E5%88%A0%E9%99%A4%E6%9C%89%E5%BA%8F%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E9%87%8D%E5%A4%8D%E9%A1%B9.md) | 数组、双指针 | 简单 | | 0027 | [移除元素](https://leetcode.cn/problems/remove-element/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0027.%20%E7%A7%BB%E9%99%A4%E5%85%83%E7%B4%A0.md) | 数组、双指针 | 简单 | | 0028 | [实现 strStr()](https://leetcode.cn/problems/implement-strstr/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0028.%20%E5%AE%9E%E7%8E%B0%20strStr%28%29.md) | 字符串、双指针 | 简单 | @@ -76,6 +77,7 @@ | 0089 | [格雷编码](https://leetcode.cn/problems/gray-code/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0089.%20%E6%A0%BC%E9%9B%B7%E7%BC%96%E7%A0%81.md) | 位运算、数学、回溯 | 中等 | | 0090 | [子集 II](https://leetcode.cn/problems/subsets-ii/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0090.%20%E5%AD%90%E9%9B%86%20II.md) | 位运算、数组、回溯 | 中等 | | 0091 | [解码方法](https://leetcode.cn/problems/decode-ways/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0091.%20%E8%A7%A3%E7%A0%81%E6%96%B9%E6%B3%95.md) | 字符串、动态规划 | 中等 | +| 0092 | [反转链表 II ](https://leetcode.cn/problems/reverse-linked-list-ii/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0092.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8%20II%20.md) | 链表 | 中等 | | 0093 | [复原 IP 地址](https://leetcode.cn/problems/restore-ip-addresses/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0093.%20%E5%A4%8D%E5%8E%9F%20IP%20%E5%9C%B0%E5%9D%80.md) | 字符串、回溯 | 中等 | | 0094 | [二叉树的中序遍历](https://leetcode.cn/problems/binary-tree-inorder-traversal/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0094.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E4%B8%AD%E5%BA%8F%E9%81%8D%E5%8E%86.md) | 栈、树、哈希表 | 简单 | | 0095 | [不同的二叉搜索树 II](https://leetcode.cn/problems/unique-binary-search-trees-ii/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0095.%20%E4%B8%8D%E5%90%8C%E7%9A%84%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%20II.md) | 树、二叉搜索树、动态规划、回溯、二叉树 | 中等 | @@ -458,6 +460,7 @@ | 1095 | [山脉数组中查找目标值](https://leetcode.cn/problems/find-in-mountain-array/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1095.%20%E5%B1%B1%E8%84%89%E6%95%B0%E7%BB%84%E4%B8%AD%E6%9F%A5%E6%89%BE%E7%9B%AE%E6%A0%87%E5%80%BC.md) | 数组、二分查找、交互 | 困难 | | 1099 | [小于 K 的两数之和](https://leetcode.cn/problems/two-sum-less-than-k/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1099.%20%E5%B0%8F%E4%BA%8E%20K%20%E7%9A%84%E4%B8%A4%E6%95%B0%E4%B9%8B%E5%92%8C.md) | 数组、双指针、二分查找、排序 | 简单 | | 1100 | [长度为 K 的无重复字符子串](https://leetcode.cn/problems/find-k-length-substrings-with-no-repeated-characters/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1100.%20%E9%95%BF%E5%BA%A6%E4%B8%BA%20K%20%E7%9A%84%E6%97%A0%E9%87%8D%E5%A4%8D%E5%AD%97%E7%AC%A6%E5%AD%90%E4%B8%B2.md) | 哈希表、字符串、滑动窗口 | 中等 | +| 1108 | [IP 地址无效化](https://leetcode.cn/problems/defanging-an-ip-address/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1108.%20IP%20%E5%9C%B0%E5%9D%80%E6%97%A0%E6%95%88%E5%8C%96.md) | 字符串 | 简单 | | 1109 | [航班预订统计](https://leetcode.cn/problems/corporate-flight-bookings/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1109.%20%E8%88%AA%E7%8F%AD%E9%A2%84%E8%AE%A2%E7%BB%9F%E8%AE%A1.md) | 数组、前缀和 | 中等 | | 1122 | [数组的相对排序](https://leetcode.cn/problems/relative-sort-array/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1122.%20%E6%95%B0%E7%BB%84%E7%9A%84%E7%9B%B8%E5%AF%B9%E6%8E%92%E5%BA%8F.md) | 数组、哈希表、计数排序、排序 | 简单 | | 1136 | [平行课程](https://leetcode.cn/problems/parallel-courses/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1136.%20%E5%B9%B3%E8%A1%8C%E8%AF%BE%E7%A8%8B.md) | 图、拓扑排序 | 中等 | diff --git a/Contents/00.Introduction/05.Categories-List.md b/Contents/00.Introduction/05.Categories-List.md index 31746da9..fac87086 100644 --- a/Contents/00.Introduction/05.Categories-List.md +++ b/Contents/00.Introduction/05.Categories-List.md @@ -275,8 +275,8 @@ | 0083 | [删除排序链表中的重复元素](https://leetcode.cn/problems/remove-duplicates-from-sorted-list/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0083.%20%E5%88%A0%E9%99%A4%E6%8E%92%E5%BA%8F%E9%93%BE%E8%A1%A8%E4%B8%AD%E7%9A%84%E9%87%8D%E5%A4%8D%E5%85%83%E7%B4%A0.md) | 链表 | 简单 | | 0082 | [删除排序链表中的重复元素 II](https://leetcode.cn/problems/remove-duplicates-from-sorted-list-ii/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0082.%20%E5%88%A0%E9%99%A4%E6%8E%92%E5%BA%8F%E9%93%BE%E8%A1%A8%E4%B8%AD%E7%9A%84%E9%87%8D%E5%A4%8D%E5%85%83%E7%B4%A0%20II.md) | 链表、双指针 | 中等 | | 0206 | [反转链表](https://leetcode.cn/problems/reverse-linked-list/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0206.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8.md) | 链表 | 简单 | -| 0092 | 反转链表 II | | | | -| 0025 | K 个一组翻转链表 | | | | +| 0092 | [反转链表 II ](https://leetcode.cn/problems/reverse-linked-list-ii/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0092.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8%20II%20.md) | 链表 | 中等 | +| 0025 | [K 个一组翻转链表](https://leetcode.cn/problems/reverse-nodes-in-k-group/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0025.%20K%20%E4%B8%AA%E4%B8%80%E7%BB%84%E7%BF%BB%E8%BD%AC%E9%93%BE%E8%A1%A8.md) | 递归、链表 | 困难 | | 0203 | [移除链表元素](https://leetcode.cn/problems/remove-linked-list-elements/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0203.%20%E7%A7%BB%E9%99%A4%E9%93%BE%E8%A1%A8%E5%85%83%E7%B4%A0.md) | 链表 | 简单 | | 0328 | [奇偶链表](https://leetcode.cn/problems/odd-even-linked-list/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0328.%20%E5%A5%87%E5%81%B6%E9%93%BE%E8%A1%A8.md) | 链表 | 中等 | | 0234 | [回文链表](https://leetcode.cn/problems/palindrome-linked-list/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0234.%20%E5%9B%9E%E6%96%87%E9%93%BE%E8%A1%A8.md) | 链表、双指针 | 简单 | @@ -722,7 +722,7 @@ | 0118 | [杨辉三角](https://leetcode.cn/problems/pascals-triangle/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0118.%20%E6%9D%A8%E8%BE%89%E4%B8%89%E8%A7%92.md) | 数组 | 简单 | | 0119 | [杨辉三角 II](https://leetcode.cn/problems/pascals-triangle-ii/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0119.%20%E6%9D%A8%E8%BE%89%E4%B8%89%E8%A7%92%20II.md) | 数组 | 简单 | | 0206 | [反转链表](https://leetcode.cn/problems/reverse-linked-list/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0206.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8.md) | 链表 | 简单 | -| 0092 | 反转链表 II | | | | +| 0092 | [反转链表 II ](https://leetcode.cn/problems/reverse-linked-list-ii/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0092.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8%20II%20.md) | 链表 | 中等 | | 0021 | [合并两个有序链表](https://leetcode.cn/problems/merge-two-sorted-lists/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0021.%20%E5%90%88%E5%B9%B6%E4%B8%A4%E4%B8%AA%E6%9C%89%E5%BA%8F%E9%93%BE%E8%A1%A8.md) | 递归、链表 | 简单 | | 0509 | [斐波那契数](https://leetcode.cn/problems/fibonacci-number/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0509.%20%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0.md) | 数组 | 简单 | | 0070 | [爬楼梯](https://leetcode.cn/problems/climbing-stairs/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0070.%20%E7%88%AC%E6%A5%BC%E6%A2%AF.md) | 动态规划 | 简单 | diff --git a/Contents/00.Introduction/06.Interview-100-List.md b/Contents/00.Introduction/06.Interview-100-List.md index fbd9f450..5275f540 100644 --- a/Contents/00.Introduction/06.Interview-100-List.md +++ b/Contents/00.Introduction/06.Interview-100-List.md @@ -130,8 +130,8 @@ | 0083 | [删除排序链表中的重复元素](https://leetcode.cn/problems/remove-duplicates-from-sorted-list/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0083.%20%E5%88%A0%E9%99%A4%E6%8E%92%E5%BA%8F%E9%93%BE%E8%A1%A8%E4%B8%AD%E7%9A%84%E9%87%8D%E5%A4%8D%E5%85%83%E7%B4%A0.md) | 链表 | 简单 | | 0082 | [删除排序链表中的重复元素 II](https://leetcode.cn/problems/remove-duplicates-from-sorted-list-ii/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0082.%20%E5%88%A0%E9%99%A4%E6%8E%92%E5%BA%8F%E9%93%BE%E8%A1%A8%E4%B8%AD%E7%9A%84%E9%87%8D%E5%A4%8D%E5%85%83%E7%B4%A0%20II.md) | 链表、双指针 | 中等 | | 0206 | [反转链表](https://leetcode.cn/problems/reverse-linked-list/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0206.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8.md) | 链表 | 简单 | -| 0092 | 反转链表 II | | | | -| 0025 | K 个一组翻转链表 | | | | +| 0092 | [反转链表 II ](https://leetcode.cn/problems/reverse-linked-list-ii/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0092.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8%20II%20.md) | 链表 | 中等 | +| 0025 | [K 个一组翻转链表](https://leetcode.cn/problems/reverse-nodes-in-k-group/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0025.%20K%20%E4%B8%AA%E4%B8%80%E7%BB%84%E7%BF%BB%E8%BD%AC%E9%93%BE%E8%A1%A8.md) | 递归、链表 | 困难 | | 0234 | [回文链表](https://leetcode.cn/problems/palindrome-linked-list/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0234.%20%E5%9B%9E%E6%96%87%E9%93%BE%E8%A1%A8.md) | 链表、双指针 | 简单 | ### 链表排序题目 @@ -292,7 +292,7 @@ | :------ | :------ | :------ | :------ | :------ | | 0024 | [两两交换链表中的节点](https://leetcode.cn/problems/swap-nodes-in-pairs/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0024.%20%E4%B8%A4%E4%B8%A4%E4%BA%A4%E6%8D%A2%E9%93%BE%E8%A1%A8%E4%B8%AD%E7%9A%84%E8%8A%82%E7%82%B9.md) | 递归、链表 | 中等 | | 0206 | [反转链表](https://leetcode.cn/problems/reverse-linked-list/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0206.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8.md) | 链表 | 简单 | -| 0092 | 反转链表 II | | | | +| 0092 | [反转链表 II ](https://leetcode.cn/problems/reverse-linked-list-ii/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0092.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8%20II%20.md) | 链表 | 中等 | | 0021 | [合并两个有序链表](https://leetcode.cn/problems/merge-two-sorted-lists/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0021.%20%E5%90%88%E5%B9%B6%E4%B8%A4%E4%B8%AA%E6%9C%89%E5%BA%8F%E9%93%BE%E8%A1%A8.md) | 递归、链表 | 简单 | | 0070 | [爬楼梯](https://leetcode.cn/problems/climbing-stairs/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0070.%20%E7%88%AC%E6%A5%BC%E6%A2%AF.md) | 动态规划 | 简单 | | 0104 | [二叉树的最大深度](https://leetcode.cn/problems/maximum-depth-of-binary-tree/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0104.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E6%9C%80%E5%A4%A7%E6%B7%B1%E5%BA%A6.md) | 树、深度优先搜索、递归 | 简单 | diff --git a/Contents/00.Introduction/07.Interview-200-List.md b/Contents/00.Introduction/07.Interview-200-List.md index e386c914..fe1b636e 100644 --- a/Contents/00.Introduction/07.Interview-200-List.md +++ b/Contents/00.Introduction/07.Interview-200-List.md @@ -178,8 +178,8 @@ | 0083 | [删除排序链表中的重复元素](https://leetcode.cn/problems/remove-duplicates-from-sorted-list/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0083.%20%E5%88%A0%E9%99%A4%E6%8E%92%E5%BA%8F%E9%93%BE%E8%A1%A8%E4%B8%AD%E7%9A%84%E9%87%8D%E5%A4%8D%E5%85%83%E7%B4%A0.md) | 链表 | 简单 | | 0082 | [删除排序链表中的重复元素 II](https://leetcode.cn/problems/remove-duplicates-from-sorted-list-ii/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0082.%20%E5%88%A0%E9%99%A4%E6%8E%92%E5%BA%8F%E9%93%BE%E8%A1%A8%E4%B8%AD%E7%9A%84%E9%87%8D%E5%A4%8D%E5%85%83%E7%B4%A0%20II.md) | 链表、双指针 | 中等 | | 0206 | [反转链表](https://leetcode.cn/problems/reverse-linked-list/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0206.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8.md) | 链表 | 简单 | -| 0092 | 反转链表 II | | | | -| 0025 | K 个一组翻转链表 | | | | +| 0092 | [反转链表 II ](https://leetcode.cn/problems/reverse-linked-list-ii/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0092.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8%20II%20.md) | 链表 | 中等 | +| 0025 | [K 个一组翻转链表](https://leetcode.cn/problems/reverse-nodes-in-k-group/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0025.%20K%20%E4%B8%AA%E4%B8%80%E7%BB%84%E7%BF%BB%E8%BD%AC%E9%93%BE%E8%A1%A8.md) | 递归、链表 | 困难 | | 0328 | [奇偶链表](https://leetcode.cn/problems/odd-even-linked-list/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0328.%20%E5%A5%87%E5%81%B6%E9%93%BE%E8%A1%A8.md) | 链表 | 中等 | | 0234 | [回文链表](https://leetcode.cn/problems/palindrome-linked-list/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0234.%20%E5%9B%9E%E6%96%87%E9%93%BE%E8%A1%A8.md) | 链表、双指针 | 简单 | | 0138 | [复制带随机指针的链表](https://leetcode.cn/problems/copy-list-with-random-pointer/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0138.%20%E5%A4%8D%E5%88%B6%E5%B8%A6%E9%9A%8F%E6%9C%BA%E6%8C%87%E9%92%88%E7%9A%84%E9%93%BE%E8%A1%A8.md) | 链表、哈希表 | 中等 | @@ -406,7 +406,7 @@ | :------ | :------ | :------ | :------ | :------ | | 0024 | [两两交换链表中的节点](https://leetcode.cn/problems/swap-nodes-in-pairs/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0024.%20%E4%B8%A4%E4%B8%A4%E4%BA%A4%E6%8D%A2%E9%93%BE%E8%A1%A8%E4%B8%AD%E7%9A%84%E8%8A%82%E7%82%B9.md) | 递归、链表 | 中等 | | 0206 | [反转链表](https://leetcode.cn/problems/reverse-linked-list/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0206.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8.md) | 链表 | 简单 | -| 0092 | 反转链表 II | | | | +| 0092 | [反转链表 II ](https://leetcode.cn/problems/reverse-linked-list-ii/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0092.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8%20II%20.md) | 链表 | 中等 | | 0021 | [合并两个有序链表](https://leetcode.cn/problems/merge-two-sorted-lists/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0021.%20%E5%90%88%E5%B9%B6%E4%B8%A4%E4%B8%AA%E6%9C%89%E5%BA%8F%E9%93%BE%E8%A1%A8.md) | 递归、链表 | 简单 | | 0509 | [斐波那契数](https://leetcode.cn/problems/fibonacci-number/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0509.%20%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0.md) | 数组 | 简单 | | 0070 | [爬楼梯](https://leetcode.cn/problems/climbing-stairs/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0070.%20%E7%88%AC%E6%A5%BC%E6%A2%AF.md) | 动态规划 | 简单 | diff --git a/Contents/02.Linked-List/01.Linked-List-Basic/02.Linked-List-Basic-List.md b/Contents/02.Linked-List/01.Linked-List-Basic/02.Linked-List-Basic-List.md index d24a2d38..6d4c6736 100644 --- a/Contents/02.Linked-List/01.Linked-List-Basic/02.Linked-List-Basic-List.md +++ b/Contents/02.Linked-List/01.Linked-List-Basic/02.Linked-List-Basic-List.md @@ -6,8 +6,8 @@ | 0083 | [删除排序链表中的重复元素](https://leetcode.cn/problems/remove-duplicates-from-sorted-list/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0083.%20%E5%88%A0%E9%99%A4%E6%8E%92%E5%BA%8F%E9%93%BE%E8%A1%A8%E4%B8%AD%E7%9A%84%E9%87%8D%E5%A4%8D%E5%85%83%E7%B4%A0.md) | 链表 | 简单 | | 0082 | [删除排序链表中的重复元素 II](https://leetcode.cn/problems/remove-duplicates-from-sorted-list-ii/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0082.%20%E5%88%A0%E9%99%A4%E6%8E%92%E5%BA%8F%E9%93%BE%E8%A1%A8%E4%B8%AD%E7%9A%84%E9%87%8D%E5%A4%8D%E5%85%83%E7%B4%A0%20II.md) | 链表、双指针 | 中等 | | 0206 | [反转链表](https://leetcode.cn/problems/reverse-linked-list/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0206.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8.md) | 链表 | 简单 | -| 0092 | 反转链表 II | | | | -| 0025 | K 个一组翻转链表 | | | | +| 0092 | [反转链表 II ](https://leetcode.cn/problems/reverse-linked-list-ii/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0092.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8%20II%20.md) | 链表 | 中等 | +| 0025 | [K 个一组翻转链表](https://leetcode.cn/problems/reverse-nodes-in-k-group/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0025.%20K%20%E4%B8%AA%E4%B8%80%E7%BB%84%E7%BF%BB%E8%BD%AC%E9%93%BE%E8%A1%A8.md) | 递归、链表 | 困难 | | 0203 | [移除链表元素](https://leetcode.cn/problems/remove-linked-list-elements/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0203.%20%E7%A7%BB%E9%99%A4%E9%93%BE%E8%A1%A8%E5%85%83%E7%B4%A0.md) | 链表 | 简单 | | 0328 | [奇偶链表](https://leetcode.cn/problems/odd-even-linked-list/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0328.%20%E5%A5%87%E5%81%B6%E9%93%BE%E8%A1%A8.md) | 链表 | 中等 | | 0234 | [回文链表](https://leetcode.cn/problems/palindrome-linked-list/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0234.%20%E5%9B%9E%E6%96%87%E9%93%BE%E8%A1%A8.md) | 链表、双指针 | 简单 | diff --git a/Contents/09.Algorithm-Base/02.Recursive-Algorithm/02.Recursive-Algorithm-List.md b/Contents/09.Algorithm-Base/02.Recursive-Algorithm/02.Recursive-Algorithm-List.md index c291768e..6f7017c3 100644 --- a/Contents/09.Algorithm-Base/02.Recursive-Algorithm/02.Recursive-Algorithm-List.md +++ b/Contents/09.Algorithm-Base/02.Recursive-Algorithm/02.Recursive-Algorithm-List.md @@ -7,7 +7,7 @@ | 0118 | [杨辉三角](https://leetcode.cn/problems/pascals-triangle/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0118.%20%E6%9D%A8%E8%BE%89%E4%B8%89%E8%A7%92.md) | 数组 | 简单 | | 0119 | [杨辉三角 II](https://leetcode.cn/problems/pascals-triangle-ii/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0119.%20%E6%9D%A8%E8%BE%89%E4%B8%89%E8%A7%92%20II.md) | 数组 | 简单 | | 0206 | [反转链表](https://leetcode.cn/problems/reverse-linked-list/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0206.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8.md) | 链表 | 简单 | -| 0092 | 反转链表 II | | | | +| 0092 | [反转链表 II ](https://leetcode.cn/problems/reverse-linked-list-ii/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0092.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8%20II%20.md) | 链表 | 中等 | | 0021 | [合并两个有序链表](https://leetcode.cn/problems/merge-two-sorted-lists/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0021.%20%E5%90%88%E5%B9%B6%E4%B8%A4%E4%B8%AA%E6%9C%89%E5%BA%8F%E9%93%BE%E8%A1%A8.md) | 递归、链表 | 简单 | | 0509 | [斐波那契数](https://leetcode.cn/problems/fibonacci-number/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0509.%20%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0.md) | 数组 | 简单 | | 0070 | [爬楼梯](https://leetcode.cn/problems/climbing-stairs/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0070.%20%E7%88%AC%E6%A5%BC%E6%A2%AF.md) | 动态规划 | 简单 | diff --git a/README.md b/README.md index f8d3be67..ba26c3bd 100644 --- a/README.md +++ b/README.md @@ -254,4 +254,4 @@ - [动态规划优化题目](./Contents/10.Dynamic-Programming/11.DP-Optimization/04.DP-Optimization-List.md) ## 11. 附加内容 -## [12. LeetCode 题解(已完成 712 道)](./Contents/00.Introduction/04.Solutions-List.md) \ No newline at end of file +## [12. LeetCode 题解(已完成 715 道)](./Contents/00.Introduction/04.Solutions-List.md) \ No newline at end of file diff --git "a/Solutions/0025. K 344円270円252円344円270円200円347円273円204円347円277円273円350円275円254円351円223円276円350円241円250円.md" "b/Solutions/0025. K 344円270円252円344円270円200円347円273円204円347円277円273円350円275円254円351円223円276円350円241円250円.md" new file mode 100644 index 00000000..c7aecfe2 --- /dev/null +++ "b/Solutions/0025. K 344円270円252円344円270円200円347円273円204円347円277円273円350円275円254円351円223円276円350円241円250円.md" @@ -0,0 +1,96 @@ +## [0025. K 个一组翻转链表](https://leetcode.cn/problems/reverse-nodes-in-k-group/) + +- 标签: 递归、链表 +- 难度:困难 + +## 题目大意 + +**描述**:给你链表的头节点 `head` ,再给定一个正整数 `k`,`k` 的值小于或等于链表的长度。 + +**要求**:每 `k` 个节点一组进行翻转,并返回修改后的链表。如果链表节点总数不是 `k` 的整数倍,则将最后剩余的节点保持原有顺序。 + +**说明**: + +- 不能只是单纯的改变节点内部的值,而是需要实际进行节点交换。 +- 假设链表中的节点数目为 `n`。 +- 1ドル \le k \le n \le 5000$。 +- 0ドル \le Node.val \le 1000$。 +- 要求设计一个只用 `O(1)` 额外内存空间的算法解决此问题。 + +**示例**: + +```Python +输入 head = [1,2,3,4,5], k = 2 +输出 [2,1,4,3,5] +``` + +## 解题思路 + +### 思路 1:迭代 + +在「[0206. 反转链表](https://leetcode.cn/problems/reverse-linked-list/)」中我们可以通过迭代、递归两种方法将整个链表反转。而这道题要求以 `k` 为单位,对链表的区间进行反转。而区间反转其实就是「[0092. 反转链表 II ](https://leetcode.cn/problems/reverse-linked-list-ii/)」这道题的题目要求。 + +本题中,我们可以以 `k` 为单位对链表进行切分,然后分别对每个区间部分进行反转。最后再返回头节点即可。 + +但是需要注意一点,如果需要反转的区间包含了链表的第一个节点,那么我们可以事先创建一个哑节点作为链表初始位置开始遍历,这样就能避免找不到需要反转的链表区间的前一个节点。 + +这道题的具体解题步骤如下: + +1. 先使用哑节点 `dummy_head` 构造一个指向 `head` 的指针,避免找不到需要反转的链表区间的前一个节点。使用变量 `index` 记录当前元素的序号。 +2. 使用两个指针 `cur`、`tail` 分别表示链表中待反转区间的首尾节点。初始 `cur` 赋值为 `dummy_head`,`tail` 赋值为 `dummy_head.next`,也就是 `head`。 +3. 将 `tail` 向右移动,每移动一步,就领 `index` 加 `1`。 + 1. 当 `index % k != 0` 时,直接将 `tail` 向右移动,直到移动到当前待反转区间的结尾位置。 + 2. 当 `index % k == 0` 时,说明 `tail` 已经移动到了当前待反转区间的结尾位置,此时调用 `cur = self.reverse(cur, tail.next)` ,将待反转区间进行反转,并返回反转后区间的起始节点赋值给当前反转区间的首节点 `cur`。然后将 `tail` 移动到 `cur` 的下一个节点。 +4. 最后返回新的头节点 `dummy_head.next`。 + +关于 `def reverse(self, head, tail):` 方法这里也说下具体步骤: + +1. `head` 代表当前待反转区间的第一个节点的前一个节点,`tail` 代表当前待反转区间的最后一个节点的后一个节点。 +2. 先用 `first` 保存一下待反转区间的第一个节点(反转之后为区间的尾节点),方便反转之后进行连接。 +3. 我们使用两个指针 `cur` 和 `pre` 进行迭代。`pre` 指向 `cur` 前一个节点位置,即 `pre` 指向需要反转节点的前一个节点,`cur` 指向需要反转的节点。初始时,`pre` 指向待反转区间的第一个节点的前一个节点 `head`,`cur` 指向待反转区间的第一个节点,即 `pre.next`。 +4. 当当前节点 `cur` 不等于 `tail` 时,将 `pre` 和 `cur` 的前后指针进行交换,指针更替顺序为: + 1. 使用 `next` 指针保存当前节点 `cur` 的后一个节点,即 `next = cur.next`; + 2. 断开当前节点 `cur` 的后一节点链接,将 `cur` 的 `next` 指针指向前一节点 `pre`,即 `cur.next = pre`; + 3. `pre` 向前移动一步,移动到 `cur` 位置,即 `pre = cur`; + 4. `cur` 向前移动一步,移动到之前 `next` 指针保存的位置,即 `cur = next`。 +5. 继续执行第 `4` 步中的 `1`、`2`、`3`、`4`步。 +6. 最后等到 `cur` 遍历到链表末尾(即 `cur == tail`)时,令「当前待反转区间的第一个节点的前一个节点」指向「反转区间后的头节点」 ,即 `head.next = pre`。令「待反转区间的第一个节点(反转之后为区间的尾节点)」指向「待反转分区间的最后一个节点的后一个节点」,即 `first.next = tail`。 +7. 最后返回新的头节点 `dummy_head.next`。 + +### 思路 1:迭代代码 + +```Python +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def reverse(self, head, tail): + pre = head + cur = pre.next + first = cur + while cur != tail: + next = cur.next + cur.next = pre + pre = cur + cur = next + head.next = pre + first.next = tail + return first + + def reverseKGroup(self, head: ListNode, k: int) -> ListNode: + dummy_head = ListNode(0) + dummy_head.next = head + cur = dummy_head + tail = dummy_head.next + index = 0 + while tail: + index += 1 + if index % k == 0: + cur = self.reverse(cur, tail.next) + tail = cur.next + else: + tail = tail.next + return dummy_head.next +``` diff --git "a/Solutions/0092. 345円217円215円350円275円254円351円223円276円350円241円250円 II.md" "b/Solutions/0092. 345円217円215円350円275円254円351円223円276円350円241円250円 II.md" new file mode 100644 index 00000000..24481353 --- /dev/null +++ "b/Solutions/0092. 345円217円215円350円275円254円351円223円276円350円241円250円 II.md" @@ -0,0 +1,88 @@ +## [0092. 反转链表 II ](https://leetcode.cn/problems/reverse-linked-list-ii/) + +- 标签:链表 +- 难度:中等 + +## 题目大意 + +**描述**:给定单链表的头指针 `head` 和两个整数 `left` 和 `right` ,其中 `left <= right`。 + +**要求**:反转从位置 `left` 到位置 `right` 的链表节点,返回反转后的链表 。 + +**说明**: + +- 链表中节点数目为 `n`。 +- 1ドル \le n \le 500$。 +- $-500 \le Node.val \le 500$。 +- 1ドル \le left \le right \le n$。 + +**示例**: + +```Python +输入 head = [1,2,3,4,5], left = 2, right = 4 +输出 [1,4,3,2,5] +``` + +## 解题思路 + +### 思路 1:迭代 + +在「[0206. 反转链表](https://leetcode.cn/problems/reverse-linked-list/)」中我们可以通过迭代、递归两种方法将整个链表反转。而这道题要求对链表的部分区间进行反转。我们可以先遍历到需要反转的链表区间的前一个节点,然后对需要反转的链表区间进行迭代反转。最后再返回头节点即可。 + +但是需要注意一点,如果需要反转的区间包含了链表的第一个节点,那么我们可以事先创建一个哑节点作为链表初始位置开始遍历,这样就能避免找不到需要反转的链表区间的前一个节点。 + +这道题的具体解题步骤如下: + +1. 先使用哑节点 `dummy_head` 构造一个指向 `head` 的指针,使得可以从 `head` 开始遍历。使用 `index` 记录当前元素的序号。 +2. 我们使用一个指针 `reverse_start`,初始赋值为 `dummy_head`。然后向右逐步移动到需要反转的区间的前一个节点。 +3. 然后再使用两个指针 `cur` 和 `pre` 进行迭代。`pre` 指向 `cur` 前一个节点位置,即 `pre` 指向需要反转节点的前一个节点,`cur` 指向需要反转的节点。初始时,`pre` 指向 `reverse_start`,`cur` 指向 `pre.next`。 +4. 当当前节点 `cur` 不为空,且 `index` 在反转区间内时,将 `pre` 和 `cur` 的前后指针进行交换,指针更替顺序为: + 1. 使用 `next` 指针保存当前节点 `cur` 的后一个节点,即 `next = cur.next`; + 2. 断开当前节点 `cur` 的后一节点链接,将 `cur` 的 `next` 指针指向前一节点 `pre`,即 `cur.next = pre`; + 3. `pre` 向前移动一步,移动到 `cur` 位置,即 `pre = cur`; + 4. `cur` 向前移动一步,移动到之前 `next` 指针保存的位置,即 `cur = next`。 + 5. 然后令 `index` 加 `1`。 +5. 继续执行第 `4` 步中的 `1`、`2`、`3`、`4`、`5` 步。 +6. 最后等到 `cur` 遍历到链表末尾(即 `cur == None`)或者遍历到需要反转区间的末尾时(即 `index> right`) 时,将反转区间的头尾节点分别与之前保存的需要反转的区间的前一个节点 `reverse_start` 相连,即 `reverse_start.next.next = cur`,`reverse_start.next = pre`。 +7. 最后返回新的头节点 `dummy_head.next`。 + +### 思路 1:迭代代码 + +```Python +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def reverseBetween(self, head: ListNode, left: int, right: int) -> ListNode: + index = 1 + dummy_head = ListNode(0) + dummy_head.next = head + pre = dummy_head + + reverse_start = dummy_head + while reverse_start.next and index < left: + reverse_start = reverse_start.next + index += 1 + + pre = reverse_start + cur = pre.next + while cur and index <= right: + next = cur.next + cur.next = pre + pre = cur + cur = next + index += 1 + + reverse_start.next.next = cur + reverse_start.next = pre + + return dummy_head.next +``` + +## 参考资料 + +- 【题解】[动画图解:翻转链表的指定区间 - 反转链表 II - 力扣](https://leetcode.cn/problems/reverse-linked-list-ii/solution/dong-hua-tu-jie-fan-zhuan-lian-biao-de-z-n4px/) +- 【题解】[【宫水三叶】一个能应用所有「链表」题里的「哨兵」技巧 - 反转链表 II - 力扣](https://leetcode.cn/problems/reverse-linked-list-ii/solution/yi-ge-neng-ying-yong-suo-you-lian-biao-t-vjx6/) + diff --git "a/Solutions/0206. 345円217円215円350円275円254円351円223円276円350円241円250円.md" "b/Solutions/0206. 345円217円215円350円275円254円351円223円276円350円241円250円.md" index 55dd0326..f684019f 100644 --- "a/Solutions/0206. 345円217円215円350円275円254円351円223円276円350円241円250円.md" +++ "b/Solutions/0206. 345円217円215円350円275円254円351円223円276円350円241円250円.md" @@ -9,18 +9,25 @@ **要求**:将该单链表进行反转。可以迭代或递归地反转链表。 -比如: +**说明**: -``` -翻转前: -1->2->3->4->5->NULL -反转后: -5->4->3->2->1->NULL +- 链表中节点的数目范围是 $[0, 5000]$。 +- $-5000 \le Node.val \le 5000$。 + +**示例**: + +```Python +输入 head = [1,2,3,4,5] +输出 [5,4,3,2,1] + +解释 +翻转前 1->2->3->4->5->NULL +反转后 5->4->3->2->1->NULL ``` ## 解题思路 -### 思路 1. 迭代 +### 思路 1:迭代 1. 使用两个指针 `cur` 和 `pre` 进行迭代。`pre` 指向 `cur` 前一个节点位置。初始时,`pre` 指向 `None`,`cur` 指向 `head`。 @@ -36,7 +43,22 @@ ![](https://qcdn.itcharge.cn/images/20220111133639.png) -### 思路 2. 递归 +### 思路 1:迭代代码 + +```Python +class Solution: + def reverseList(self, head: ListNode) -> ListNode: + pre = None + cur = head + while cur != None: + next = cur.next + cur.next = pre + pre = cur + cur = next + return pre +``` + +### 思路 2:递归 具体做法如下: @@ -52,24 +74,7 @@ ![](https://qcdn.itcharge.cn/images/20220111134246.png) -## 代码 - -1. 迭代 - -```Python -class Solution: - def reverseList(self, head: ListNode) -> ListNode: - pre = None - cur = head - while cur != None: - next = cur.next - cur.next = pre - pre = cur - cur = next - return pre -``` - -2. 递归 +### 思路 2:递归代码 ```Python class Solution: diff --git "a/Solutions/0513. 346円211円276円346円240円221円345円267円246円344円270円213円350円247円222円347円232円204円345円200円274円.md" "b/Solutions/0513. 346円211円276円346円240円221円345円267円246円344円270円213円350円247円222円347円232円204円345円200円274円.md" index 166a2220..e2df5f1f 100644 --- "a/Solutions/0513. 346円211円276円346円240円221円345円267円246円344円270円213円350円247円222円347円232円204円345円200円274円.md" +++ "b/Solutions/0513. 346円211円276円346円240円221円345円267円246円344円270円213円350円247円222円347円232円204円345円200円274円.md" @@ -5,17 +5,40 @@ ## 题目大意 -给定一个二叉树的根节点 `root`,找出该二叉树 「最底层」的「最左边」节点的值。 +**描述**:给定一个二叉树的根节点 `root`。 + +**要求**:找出该二叉树 「最底层」的「最左边」节点的值。 + +**说明**: + +- 假设二叉树中至少有一个节点。 +- 二叉树的节点个数的范围是 $[1,10^4]$。 +- $-2^{31} \le Node.val \le 2^{31} - 1$。 + +**示例**: + +```Python +输入 [1,2,3,4,null,5,6,null,null,7] +输出 7 +``` + +![](https://assets.leetcode.com/uploads/2020/12/14/tree2.jpg) ## 解题思路 -这个问题拆开来看,一是如何找到「最底层」,而是在「最底层」如何找到最左边的节点。 +### 思路 1:层序遍历 + +这个问题可以拆分为两个问题: + +1. 如何找到「最底层」。 +2. 在「最底层」如何找到最左边的节点。 -通过层序遍历,我们可以直接确定最底层节点。而「最底层」的「最左边」节点可以改变层序遍历的左右节点访问顺序。 +第一个问题,我们可以通过层序遍历直接确定最底层节点。而第二个问题可以通过改变层序遍历的左右节点访问顺序从而找到「最底层」的「最左边节点」。具体方法如下: -每层元素先访问右节点,在访问左节点,则最后一个遍历的元素就是「最底层」的「最左边」节点,即左下角的节点,返回该点对应的值即可。 +1. 对二叉树进行层序遍历。每层元素先访问右节点,再访问左节点。 +2. 当遍历到最后一个元素时,此时最后一个元素就是「最底层」的「最左边」节点,即左下角的节点,将该节点的值返回即可。 -## 代码 +### 思路 1:层序遍历代码 ```Python import collections diff --git "a/Solutions/1108. IP 345円234円260円345円235円200円346円227円240円346円225円210円345円214円226円.md" "b/Solutions/1108. IP 345円234円260円345円235円200円346円227円240円346円225円210円345円214円226円.md" new file mode 100644 index 00000000..0060846f --- /dev/null +++ "b/Solutions/1108. IP 345円234円260円345円235円200円346円227円240円346円225円210円345円214円226円.md" @@ -0,0 +1,35 @@ +## [1108. IP 地址无效化](https://leetcode.cn/problems/defanging-an-ip-address/) + +- 标签:字符串 +- 难度:简单 + +## 题目大意 + +**描述**:给定一个有效的 IPv4 的地址 `address`。。 + +**要求**:返回这个 IP 地址的无效化版本。 + +**说明**: + +- **无效化 IP 地址**:其实就是用 `"[.]"` 代替了每个 `"."`。 + +**示例**: + +```Python +输入 address = "255.100.50.0" +输出 "255[.]100[.]50[.]0" +``` + +## 解题思路 + +### 思路 1:字符串替换 + +依次将字符串 `address` 中的 `"."` 替换为 `"[.]"`。这里为了方便,直接调用了 `replace` 方法。 + +### 思路 1:字符串替换代码 + +```Python +class Solution: + def defangIPaddr(self, address: str) -> str: + return address.replace('.', '[.]') +```

AltStyle によって変換されたページ (->オリジナル) /