diff --git a/README.md b/README.md index b5aa68cf43328..52819317fa293 100644 --- a/README.md +++ b/README.md @@ -20,219 +20,219 @@ ## 站点 -- Netlify: https://lc.netlify.app -- GitHub Pages: https://doocs.github.io/leetcode +- Gitee Pages: https://doocs.gitee.io/leetcode +- GitHub Pages: https://doocs.github.io/leetcode ## 算法全解 -- [LeetCode](/solution/README.md) -- [剑指 Offer(第 2 版)](/lcof/README.md) -- [剑指 Offer(专项突击版)](/lcof2/README.md) -- [程序员面试金典(第 6 版)](/lcci/README.md) +- [LeetCode](/solution/README.md) +- [剑指 Offer(第 2 版)](/lcof/README.md) +- [剑指 Offer(专项突击版)](/lcof2/README.md) +- [程序员面试金典(第 6 版)](/lcci/README.md) ## 基础算法通关 ### 排序算法 -- [冒泡排序](/basic/sorting/BubbleSort/README.md) -- [插入排序](/basic/sorting/InsertionSort/README.md) -- [选择排序](/basic/sorting/SelectionSort/README.md) -- [归并排序(算法模板)](/basic/sorting/MergeSort/README.md) -- [快速排序(算法模板)](/basic/sorting/QuickSort/README.md) -- [希尔排序](/basic/sorting/ShellSort/README.md) -- [堆排序(算法模板)](/basic/sorting/HeapSort/README.md) +- [冒泡排序](/basic/sorting/BubbleSort/README.md) +- [插入排序](/basic/sorting/InsertionSort/README.md) +- [选择排序](/basic/sorting/SelectionSort/README.md) +- [归并排序(算法模板)](/basic/sorting/MergeSort/README.md) +- [快速排序(算法模板)](/basic/sorting/QuickSort/README.md) +- [希尔排序](/basic/sorting/ShellSort/README.md) +- [堆排序(算法模板)](/basic/sorting/HeapSort/README.md) ### 查找算法 -- [二分查找(算法模板)](/basic/searching/BinarySearch/README.md) +- [二分查找(算法模板)](/basic/searching/BinarySearch/README.md) ## 高频考题 ### 数组 -- [多数元素](/solution/0100-0199/0169.Majority%20Element/README.md) -- [删除排序数组中的重复项](/solution/0000-0099/0026.Remove%20Duplicates%20from%20Sorted%20Array/README.md) -- [删除排序数组中的重复项 II](/solution/0000-0099/0080.Remove%20Duplicates%20from%20Sorted%20Array%20II/README.md) -- [移除元素](/solution/0000-0099/0027.Remove%20Element/README.md) -- [移动零](/solution/0200-0299/0283.Move%20Zeroes/README.md) -- [数组中重复的数字](/lcof/面试题03.%20数组中重复的数字/README.md) -- [旋转数组](/solution/0100-0199/0189.Rotate%20Array/README.md) -- [螺旋矩阵](/solution/0000-0099/0054.Spiral%20Matrix/README.md) -- [两数之和](/solution/0000-0099/0001.Two%20Sum/README.md) -- [三数之和](/solution/0000-0099/0015.3Sum/README.md) -- [四数之和](/solution/0000-0099/0018.4Sum/README.md) -- [较小的三数之和](/solution/0200-0299/0259.3Sum%20Smaller/README.md) -- [最接近的三数之和](/solution/0000-0099/0016.3Sum%20Closest/README.md) -- [合并两个有序数组](/solution/0000-0099/0088.Merge%20Sorted%20Array/README.md) -- [寻找旋转排序数组中的最小值](/solution/0100-0199/0153.Find%20Minimum%20in%20Rotated%20Sorted%20Array/README.md) -- [寻找旋转排序数组中的最小值 II](/solution/0100-0199/0154.Find%20Minimum%20in%20Rotated%20Sorted%20Array%20II/README.md) -- [除自身以外数组的乘积](/solution/0200-0299/0238.Product%20of%20Array%20Except%20Self/README.md) +- [多数元素](/solution/0100-0199/0169.Majority%20Element/README.md) +- [删除排序数组中的重复项](/solution/0000-0099/0026.Remove%20Duplicates%20from%20Sorted%20Array/README.md) +- [删除排序数组中的重复项 II](/solution/0000-0099/0080.Remove%20Duplicates%20from%20Sorted%20Array%20II/README.md) +- [移除元素](/solution/0000-0099/0027.Remove%20Element/README.md) +- [移动零](/solution/0200-0299/0283.Move%20Zeroes/README.md) +- [数组中重复的数字](/lcof/面试题03.%20数组中重复的数字/README.md) +- [旋转数组](/solution/0100-0199/0189.Rotate%20Array/README.md) +- [螺旋矩阵](/solution/0000-0099/0054.Spiral%20Matrix/README.md) +- [两数之和](/solution/0000-0099/0001.Two%20Sum/README.md) +- [三数之和](/solution/0000-0099/0015.3Sum/README.md) +- [四数之和](/solution/0000-0099/0018.4Sum/README.md) +- [较小的三数之和](/solution/0200-0299/0259.3Sum%20Smaller/README.md) +- [最接近的三数之和](/solution/0000-0099/0016.3Sum%20Closest/README.md) +- [合并两个有序数组](/solution/0000-0099/0088.Merge%20Sorted%20Array/README.md) +- [寻找旋转排序数组中的最小值](/solution/0100-0199/0153.Find%20Minimum%20in%20Rotated%20Sorted%20Array/README.md) +- [寻找旋转排序数组中的最小值 II](/solution/0100-0199/0154.Find%20Minimum%20in%20Rotated%20Sorted%20Array%20II/README.md) +- [除自身以外数组的乘积](/solution/0200-0299/0238.Product%20of%20Array%20Except%20Self/README.md) ### 字符串 -- [无重复字符的最长子串](/solution/0000-0099/0003.Longest%20Substring%20Without%20Repeating%20Characters/README.md) -- [最长公共前缀](/solution/0000-0099/0014.Longest%20Common%20Prefix/README.md) -- [反转字符串中的元音字母](/solution/0300-0399/0345.Reverse%20Vowels%20of%20a%20String/README.md) -- [字符串转换整数 (atoi)](/solution/0000-0099/0008.String%20to%20Integer%20%28atoi%29/README.md) -- [赎金信](/solution/0300-0399/0383.Ransom%20Note/README.md) +- [无重复字符的最长子串](/solution/0000-0099/0003.Longest%20Substring%20Without%20Repeating%20Characters/README.md) +- [最长公共前缀](/solution/0000-0099/0014.Longest%20Common%20Prefix/README.md) +- [反转字符串中的元音字母](/solution/0300-0399/0345.Reverse%20Vowels%20of%20a%20String/README.md) +- [字符串转换整数 (atoi)](/solution/0000-0099/0008.String%20to%20Integer%20%28atoi%29/README.md) +- [赎金信](/solution/0300-0399/0383.Ransom%20Note/README.md) ### 链表 -- [两数相加](/solution/0000-0099/0002.Add%20Two%20Numbers/README.md) -- [两数相加 II](/solution/0400-0499/0445.Add%20Two%20Numbers%20II/README.md) -- [从尾到头打印链表](/lcof/面试题06.%20从尾到头打印链表/README.md) -- [删除链表中的节点](/solution/0200-0299/0237.Delete%20Node%20in%20a%20Linked%20List/README.md) -- [删除排序链表中的重复元素](/solution/0000-0099/0083.Remove%20Duplicates%20from%20Sorted%20List/README.md) -- [删除排序链表中的重复元素 II](/solution/0000-0099/0082.Remove%20Duplicates%20from%20Sorted%20List%20II/README.md) -- [移除链表元素](/solution/0200-0299/0203.Remove%20Linked%20List%20Elements/README.md) -- [链表中倒数第 k 个节点](/lcci/02.02.Kth%20Node%20From%20End%20of%20List/README.md) -- [两两交换链表中的节点](/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/README.md) -- [合并两个有序链表](/solution/0000-0099/0021.Merge%20Two%20Sorted%20Lists/README.md) -- [合并 K 个排序链表](/solution/0000-0099/0023.Merge%20k%20Sorted%20Lists/README.md) -- [对链表进行插入排序](/solution/0100-0199/0147.Insertion%20Sort%20List/README.md) -- [排序链表](/solution/0100-0199/0148.Sort%20List/README.md) -- [反转链表](/solution/0200-0299/0206.Reverse%20Linked%20List/README.md) -- [反转链表 II](/solution/0000-0099/0092.Reverse%20Linked%20List%20II/README.md) -- [重排链表](/solution/0100-0199/0143.Reorder%20List/README.md) -- [旋转链表](/solution/0000-0099/0061.Rotate%20List/README.md) -- [回文链表](/solution/0200-0299/0234.Palindrome%20Linked%20List/README.md) -- [相交链表](/solution/0100-0199/0160.Intersection%20of%20Two%20Linked%20Lists/README.md) -- [奇偶链表](/solution/0300-0399/0328.Odd%20Even%20Linked%20List/README.md) -- [环形链表](/solution/0100-0199/0141.Linked%20List%20Cycle/README.md) -- [环形链表 II](/solution/0100-0199/0142.Linked%20List%20Cycle%20II/README.md) -- [设计链表](/solution/0700-0799/0707.Design%20Linked%20List/README.md) +- [两数相加](/solution/0000-0099/0002.Add%20Two%20Numbers/README.md) +- [两数相加 II](/solution/0400-0499/0445.Add%20Two%20Numbers%20II/README.md) +- [从尾到头打印链表](/lcof/面试题06.%20从尾到头打印链表/README.md) +- [删除链表中的节点](/solution/0200-0299/0237.Delete%20Node%20in%20a%20Linked%20List/README.md) +- [删除排序链表中的重复元素](/solution/0000-0099/0083.Remove%20Duplicates%20from%20Sorted%20List/README.md) +- [删除排序链表中的重复元素 II](/solution/0000-0099/0082.Remove%20Duplicates%20from%20Sorted%20List%20II/README.md) +- [移除链表元素](/solution/0200-0299/0203.Remove%20Linked%20List%20Elements/README.md) +- [链表中倒数第 k 个节点](/lcci/02.02.Kth%20Node%20From%20End%20of%20List/README.md) +- [两两交换链表中的节点](/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/README.md) +- [合并两个有序链表](/solution/0000-0099/0021.Merge%20Two%20Sorted%20Lists/README.md) +- [合并 K 个排序链表](/solution/0000-0099/0023.Merge%20k%20Sorted%20Lists/README.md) +- [对链表进行插入排序](/solution/0100-0199/0147.Insertion%20Sort%20List/README.md) +- [排序链表](/solution/0100-0199/0148.Sort%20List/README.md) +- [反转链表](/solution/0200-0299/0206.Reverse%20Linked%20List/README.md) +- [反转链表 II](/solution/0000-0099/0092.Reverse%20Linked%20List%20II/README.md) +- [重排链表](/solution/0100-0199/0143.Reorder%20List/README.md) +- [旋转链表](/solution/0000-0099/0061.Rotate%20List/README.md) +- [回文链表](/solution/0200-0299/0234.Palindrome%20Linked%20List/README.md) +- [相交链表](/solution/0100-0199/0160.Intersection%20of%20Two%20Linked%20Lists/README.md) +- [奇偶链表](/solution/0300-0399/0328.Odd%20Even%20Linked%20List/README.md) +- [环形链表](/solution/0100-0199/0141.Linked%20List%20Cycle/README.md) +- [环形链表 II](/solution/0100-0199/0142.Linked%20List%20Cycle%20II/README.md) +- [设计链表](/solution/0700-0799/0707.Design%20Linked%20List/README.md) ### 二叉树 -- [二叉树的前序遍历](/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/README.md) -- [二叉树的后序遍历](/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/README.md) -- [二叉树的中序遍历](/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/README.md) -- [对称二叉树](/solution/0100-0199/0101.Symmetric%20Tree/README.md) -- [树的子结构](/lcof/面试题26.%20树的子结构/README.md) -- [翻转二叉树](/solution/0200-0299/0226.Invert%20Binary%20Tree/README.md) -- [二叉树的层次遍历](/solution/0100-0199/0102.Binary%20Tree%20Level%20Order%20Traversal/README.md) -- [二叉树的层次遍历 II](/solution/0100-0199/0107.Binary%20Tree%20Level%20Order%20Traversal%20II/README.md) -- [二叉树的右视图](/solution/0100-0199/0199.Binary%20Tree%20Right%20Side%20View/README.md) -- [二叉树的最大深度](/solution/0100-0199/0104.Maximum%20Depth%20of%20Binary%20Tree/README.md) -- [二叉树的最小深度](/solution/0100-0199/0111.Minimum%20Depth%20of%20Binary%20Tree/README.md) -- [二叉树的所有路径](/solution/0200-0299/0257.Binary%20Tree%20Paths/README.md) -- [路径总和](/solution/0100-0199/0112.Path%20Sum/README.md) -- [路径总和 II](/solution/0100-0199/0113.Path%20Sum%20II/README.md) -- [从前序与中序遍历序列构造二叉树](/solution/0100-0199/0105.Construct%20Binary%20Tree%20from%20Preorder%20and%20Inorder%20Traversal/README.md) -- [从中序与后序遍历序列构造二叉树](/solution/0100-0199/0106.Construct%20Binary%20Tree%20from%20Inorder%20and%20Postorder%20Traversal/README.md) -- [二叉搜索树的后序遍历序列](/lcof/面试题33.%20二叉搜索树的后序遍历序列/README.md) -- [二叉搜索树迭代器](/solution/0100-0199/0173.Binary%20Search%20Tree%20Iterator/README.md) -- [二叉搜索树的最近公共祖先](/solution/0200-0299/0235.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Search%20Tree/README.md) -- [二叉树的最近公共祖先](/solution/0200-0299/0236.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree/README.md) -- [将二叉搜索树转换为单链表](/lcci/17.12.BiNode/README.md) -- [将二叉搜索树转化为排序的双向链表](/solution/0400-0499/0426.Convert%20Binary%20Search%20Tree%20to%20Sorted%20Doubly%20Linked%20List/README.md) -- [二叉树的边界](/solution/0500-0599/0545.Boundary%20of%20Binary%20Tree/README.md) -- [填充每个节点的下一个右侧节点指针](/solution/0100-0199/0116.Populating%20Next%20Right%20Pointers%20in%20Each%20Node/README.md) -- [填充每个节点的下一个右侧节点指针 II](/solution/0100-0199/0117.Populating%20Next%20Right%20Pointers%20in%20Each%20Node%20II/README.md) +- [二叉树的前序遍历](/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/README.md) +- [二叉树的后序遍历](/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/README.md) +- [二叉树的中序遍历](/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/README.md) +- [对称二叉树](/solution/0100-0199/0101.Symmetric%20Tree/README.md) +- [树的子结构](/lcof/面试题26.%20树的子结构/README.md) +- [翻转二叉树](/solution/0200-0299/0226.Invert%20Binary%20Tree/README.md) +- [二叉树的层次遍历](/solution/0100-0199/0102.Binary%20Tree%20Level%20Order%20Traversal/README.md) +- [二叉树的层次遍历 II](/solution/0100-0199/0107.Binary%20Tree%20Level%20Order%20Traversal%20II/README.md) +- [二叉树的右视图](/solution/0100-0199/0199.Binary%20Tree%20Right%20Side%20View/README.md) +- [二叉树的最大深度](/solution/0100-0199/0104.Maximum%20Depth%20of%20Binary%20Tree/README.md) +- [二叉树的最小深度](/solution/0100-0199/0111.Minimum%20Depth%20of%20Binary%20Tree/README.md) +- [二叉树的所有路径](/solution/0200-0299/0257.Binary%20Tree%20Paths/README.md) +- [路径总和](/solution/0100-0199/0112.Path%20Sum/README.md) +- [路径总和 II](/solution/0100-0199/0113.Path%20Sum%20II/README.md) +- [从前序与中序遍历序列构造二叉树](/solution/0100-0199/0105.Construct%20Binary%20Tree%20from%20Preorder%20and%20Inorder%20Traversal/README.md) +- [从中序与后序遍历序列构造二叉树](/solution/0100-0199/0106.Construct%20Binary%20Tree%20from%20Inorder%20and%20Postorder%20Traversal/README.md) +- [二叉搜索树的后序遍历序列](/lcof/面试题33.%20二叉搜索树的后序遍历序列/README.md) +- [二叉搜索树迭代器](/solution/0100-0199/0173.Binary%20Search%20Tree%20Iterator/README.md) +- [二叉搜索树的最近公共祖先](/solution/0200-0299/0235.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Search%20Tree/README.md) +- [二叉树的最近公共祖先](/solution/0200-0299/0236.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree/README.md) +- [将二叉搜索树转换为单链表](/lcci/17.12.BiNode/README.md) +- [将二叉搜索树转化为排序的双向链表](/solution/0400-0499/0426.Convert%20Binary%20Search%20Tree%20to%20Sorted%20Doubly%20Linked%20List/README.md) +- [二叉树的边界](/solution/0500-0599/0545.Boundary%20of%20Binary%20Tree/README.md) +- [填充每个节点的下一个右侧节点指针](/solution/0100-0199/0116.Populating%20Next%20Right%20Pointers%20in%20Each%20Node/README.md) +- [填充每个节点的下一个右侧节点指针 II](/solution/0100-0199/0117.Populating%20Next%20Right%20Pointers%20in%20Each%20Node%20II/README.md) ### 数学 -- [整数转罗马数字](/solution/0000-0099/0012.Integer%20to%20Roman/README.md) -- [罗马数字转整数](/solution/0000-0099/0013.Roman%20to%20Integer/README.md) -- [只出现一次的数字](/solution/0100-0199/0136.Single%20Number/README.md) -- [只出现一次的数字 II](/solution/0100-0199/0137.Single%20Number%20II/README.md) -- [只出现一次的数字 III](/solution/0200-0299/0260.Single%20Number%20III/README.md) -- [错误的集合](/solution/0600-0699/0645.Set%20Mismatch/README.md) -- [位 1 的个数](/solution/0100-0199/0191.Number%20of%201%20Bits/README.md) -- [计数质数](/solution/0200-0299/0204.Count%20Primes/README.md) -- [不用加减乘除做加法](/lcof/面试题65.%20不用加减乘除做加法/README.md) -- [丢失的数字](/solution/0200-0299/0268.Missing%20Number/README.md) +- [整数转罗马数字](/solution/0000-0099/0012.Integer%20to%20Roman/README.md) +- [罗马数字转整数](/solution/0000-0099/0013.Roman%20to%20Integer/README.md) +- [只出现一次的数字](/solution/0100-0199/0136.Single%20Number/README.md) +- [只出现一次的数字 II](/solution/0100-0199/0137.Single%20Number%20II/README.md) +- [只出现一次的数字 III](/solution/0200-0299/0260.Single%20Number%20III/README.md) +- [错误的集合](/solution/0600-0699/0645.Set%20Mismatch/README.md) +- [位 1 的个数](/solution/0100-0199/0191.Number%20of%201%20Bits/README.md) +- [计数质数](/solution/0200-0299/0204.Count%20Primes/README.md) +- [不用加减乘除做加法](/lcof/面试题65.%20不用加减乘除做加法/README.md) +- [丢失的数字](/solution/0200-0299/0268.Missing%20Number/README.md) ### 栈和队列 -- [有效的括号](/solution/0000-0099/0020.Valid%20Parentheses/README.md) -- [最小栈](/solution/0100-0199/0155.Min%20Stack/README.md) -- [队列的最大值](/lcof/面试题59%20-%20II.%20队列的最大值/README.md) -- [用栈实现队列](/solution/0200-0299/0232.Implement%20Queue%20using%20Stacks/README.md) -- [用队列实现栈](/solution/0200-0299/0225.Implement%20Stack%20using%20Queues/README.md) -- [逆波兰表达式求值](/solution/0100-0199/0150.Evaluate%20Reverse%20Polish%20Notation/README.md) -- [最近的请求次数](/solution/0900-0999/0933.Number%20of%20Recent%20Calls/README.md) -- [每日温度](/solution/0700-0799/0739.Daily%20Temperatures/README.md) -- [基本计算器 II](/solution/0200-0299/0227.Basic%20Calculator%20II/README.md) -- [下一个更大元素 I](/solution/0400-0499/0496.Next%20Greater%20Element%20I/README.md) -- [下一个更大元素 II](/solution/0500-0599/0503.Next%20Greater%20Element%20II/README.md) +- [有效的括号](/solution/0000-0099/0020.Valid%20Parentheses/README.md) +- [最小栈](/solution/0100-0199/0155.Min%20Stack/README.md) +- [队列的最大值](/lcof/面试题59%20-%20II.%20队列的最大值/README.md) +- [用栈实现队列](/solution/0200-0299/0232.Implement%20Queue%20using%20Stacks/README.md) +- [用队列实现栈](/solution/0200-0299/0225.Implement%20Stack%20using%20Queues/README.md) +- [逆波兰表达式求值](/solution/0100-0199/0150.Evaluate%20Reverse%20Polish%20Notation/README.md) +- [最近的请求次数](/solution/0900-0999/0933.Number%20of%20Recent%20Calls/README.md) +- [每日温度](/solution/0700-0799/0739.Daily%20Temperatures/README.md) +- [基本计算器 II](/solution/0200-0299/0227.Basic%20Calculator%20II/README.md) +- [下一个更大元素 I](/solution/0400-0499/0496.Next%20Greater%20Element%20I/README.md) +- [下一个更大元素 II](/solution/0500-0599/0503.Next%20Greater%20Element%20II/README.md) ### 动态规划 -- [斐波那契数](/solution/0500-0599/0509.Fibonacci%20Number/README.md) -- [第 N 个泰波那契数](/solution/1100-1199/1137.N-th%20Tribonacci%20Number/README.md) -- [爬楼梯](/solution/0000-0099/0070.Climbing%20Stairs/README.md) -- [使用最小花费爬楼梯](/solution/0700-0799/0746.Min%20Cost%20Climbing%20Stairs/README.md) -- [打家劫舍](/solution/0100-0199/0198.House%20Robber/README.md) -- [打家劫舍 II](/solution/0200-0299/0213.House%20Robber%20II/README.md) -- [删除并获得点数](/solution/0700-0799/0740.Delete%20and%20Earn/README.md) -- [跳跃游戏](/solution/0000-0099/0055.Jump%20Game/README.md) -- [跳跃游戏 II](/solution/0000-0099/0045.Jump%20Game%20II/README.md) -- [最大子序和](/solution/0000-0099/0053.Maximum%20Subarray/README.md) -- [环形子数组的最大和](/solution/0900-0999/0918.Maximum%20Sum%20Circular%20Subarray/README.md) -- [乘积最大子序列](/solution/0100-0199/0152.Maximum%20Product%20Subarray/README.md) -- [乘积为正数的最长子数组长度](/solution/1500-1599/1567.Maximum%20Length%20of%20Subarray%20With%20Positive%20Product/README.md) -- [最佳观光组合](/solution/1000-1099/1014.Best%20Sightseeing%20Pair/README.md) -- [买卖股票的最佳时机](/solution/0100-0199/0121.Best%20Time%20to%20Buy%20and%20Sell%20Stock/README.md) -- [买卖股票的最佳时机 II](/solution/0100-0199/0122.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II/README.md) -- [买卖股票的最佳时机 III](/solution/0100-0199/0123.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20III/README.md) -- [最佳买卖股票时机含冷冻期](/solution/0300-0399/0309.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Cooldown/README.md) -- [买卖股票的最佳时机含手续费](/solution/0700-0799/0714.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Transaction%20Fee/README.md) -- [单词拆分](/solution/0100-0199/0139.Word%20Break/README.md) -- [接雨水](/solution/0000-0099/0042.Trapping%20Rain%20Water/README.md) -- [等差数列划分](/solution/0400-0499/0413.Arithmetic%20Slices/README.md) -- [解码方法](/solution/0000-0099/0091.Decode%20Ways/README.md) -- [不同的二叉搜索树](/solution/0000-0099/0096.Unique%20Binary%20Search%20Trees/README.md) -- [丑数 II](/solution/0200-0299/0264.Ugly%20Number%20II/README.md) -- [杨辉三角](/solution/0100-0199/0118.Pascal%27s%20Triangle/README.md) -- [杨辉三角 II](/solution/0100-0199/0119.Pascal%27s%20Triangle%20II/README.md) -- [下降路径最小和](/solution/0900-0999/0931.Minimum%20Falling%20Path%20Sum/README.md) -- [三角形最小路径和](/solution/0100-0199/0120.Triangle/README.md) -- [矩阵区域和](/solution/1300-1399/1314.Matrix%20Block%20Sum/README.md) -- [二维区域和检索 - 矩阵不可变](/solution/0300-0399/0304.Range%20Sum%20Query%202D%20-%20Immutable/README.md) -- [不同路径](/solution/0000-0099/0062.Unique%20Paths/README.md) -- [不同路径 II](/solution/0000-0099/0063.Unique%20Paths%20II/README.md) -- [最小路径和](/solution/0000-0099/0064.Minimum%20Path%20Sum/README.md) -- [最长回文子串](/solution/0000-0099/0005.Longest%20Palindromic%20Substring/README.md) -- [最长回文子序列](.solution/0500-0599/0516.Longest%20Palindromic%20Subsequence/README.md) -- [最长递增子序列](/solution/0300-0399/0300.Longest%20Increasing%20Subsequence/README.md) -- [摆动序列](/solution/0300-0399/0376.Wiggle%20Subsequence/README.md) -- [最长公共子序列](/solution/1100-1199/1143.Longest%20Common%20Subsequence/README.md) -- [编辑距离](/solution/0000-0099/0072.Edit%20Distance/README.md) -- [零钱兑换](/solution/0300-0399/0322.Coin%20Change/README.md) -- [零钱兑换 II](/solution/0500-0599/0518.Coin%20Change%202/README.md) -- [组合总和 Ⅳ](/solution/0300-0399/0377.Combination%20Sum%20IV/README.md) -- [整数拆分](/solution/0300-0399/0343.Integer%20Break/README.md) -- [完全平方数](/solution/0200-0299/0279.Perfect%20Squares/README.md) -- [礼物的最大价值](/lcof/面试题47.%20礼物的最大价值/README.md) -- [俄罗斯套娃信封问题](/solution/0300-0399/0354.Russian%20Doll%20Envelopes/README.md) +- [斐波那契数](/solution/0500-0599/0509.Fibonacci%20Number/README.md) +- [第 N 个泰波那契数](/solution/1100-1199/1137.N-th%20Tribonacci%20Number/README.md) +- [爬楼梯](/solution/0000-0099/0070.Climbing%20Stairs/README.md) +- [使用最小花费爬楼梯](/solution/0700-0799/0746.Min%20Cost%20Climbing%20Stairs/README.md) +- [打家劫舍](/solution/0100-0199/0198.House%20Robber/README.md) +- [打家劫舍 II](/solution/0200-0299/0213.House%20Robber%20II/README.md) +- [删除并获得点数](/solution/0700-0799/0740.Delete%20and%20Earn/README.md) +- [跳跃游戏](/solution/0000-0099/0055.Jump%20Game/README.md) +- [跳跃游戏 II](/solution/0000-0099/0045.Jump%20Game%20II/README.md) +- [最大子序和](/solution/0000-0099/0053.Maximum%20Subarray/README.md) +- [环形子数组的最大和](/solution/0900-0999/0918.Maximum%20Sum%20Circular%20Subarray/README.md) +- [乘积最大子序列](/solution/0100-0199/0152.Maximum%20Product%20Subarray/README.md) +- [乘积为正数的最长子数组长度](/solution/1500-1599/1567.Maximum%20Length%20of%20Subarray%20With%20Positive%20Product/README.md) +- [最佳观光组合](/solution/1000-1099/1014.Best%20Sightseeing%20Pair/README.md) +- [买卖股票的最佳时机](/solution/0100-0199/0121.Best%20Time%20to%20Buy%20and%20Sell%20Stock/README.md) +- [买卖股票的最佳时机 II](/solution/0100-0199/0122.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II/README.md) +- [买卖股票的最佳时机 III](/solution/0100-0199/0123.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20III/README.md) +- [最佳买卖股票时机含冷冻期](/solution/0300-0399/0309.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Cooldown/README.md) +- [买卖股票的最佳时机含手续费](/solution/0700-0799/0714.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Transaction%20Fee/README.md) +- [单词拆分](/solution/0100-0199/0139.Word%20Break/README.md) +- [接雨水](/solution/0000-0099/0042.Trapping%20Rain%20Water/README.md) +- [等差数列划分](/solution/0400-0499/0413.Arithmetic%20Slices/README.md) +- [解码方法](/solution/0000-0099/0091.Decode%20Ways/README.md) +- [不同的二叉搜索树](/solution/0000-0099/0096.Unique%20Binary%20Search%20Trees/README.md) +- [丑数 II](/solution/0200-0299/0264.Ugly%20Number%20II/README.md) +- [杨辉三角](/solution/0100-0199/0118.Pascal%27s%20Triangle/README.md) +- [杨辉三角 II](/solution/0100-0199/0119.Pascal%27s%20Triangle%20II/README.md) +- [下降路径最小和](/solution/0900-0999/0931.Minimum%20Falling%20Path%20Sum/README.md) +- [三角形最小路径和](/solution/0100-0199/0120.Triangle/README.md) +- [矩阵区域和](/solution/1300-1399/1314.Matrix%20Block%20Sum/README.md) +- [二维区域和检索 - 矩阵不可变](/solution/0300-0399/0304.Range%20Sum%20Query%202D%20-%20Immutable/README.md) +- [不同路径](/solution/0000-0099/0062.Unique%20Paths/README.md) +- [不同路径 II](/solution/0000-0099/0063.Unique%20Paths%20II/README.md) +- [最小路径和](/solution/0000-0099/0064.Minimum%20Path%20Sum/README.md) +- [最长回文子串](/solution/0000-0099/0005.Longest%20Palindromic%20Substring/README.md) +- [最长回文子序列](.solution/0500-0599/0516.Longest%20Palindromic%20Subsequence/README.md) +- [最长递增子序列](/solution/0300-0399/0300.Longest%20Increasing%20Subsequence/README.md) +- [摆动序列](/solution/0300-0399/0376.Wiggle%20Subsequence/README.md) +- [最长公共子序列](/solution/1100-1199/1143.Longest%20Common%20Subsequence/README.md) +- [编辑距离](/solution/0000-0099/0072.Edit%20Distance/README.md) +- [零钱兑换](/solution/0300-0399/0322.Coin%20Change/README.md) +- [零钱兑换 II](/solution/0500-0599/0518.Coin%20Change%202/README.md) +- [组合总和 Ⅳ](/solution/0300-0399/0377.Combination%20Sum%20IV/README.md) +- [整数拆分](/solution/0300-0399/0343.Integer%20Break/README.md) +- [完全平方数](/solution/0200-0299/0279.Perfect%20Squares/README.md) +- [礼物的最大价值](/lcof/面试题47.%20礼物的最大价值/README.md) +- [俄罗斯套娃信封问题](/solution/0300-0399/0354.Russian%20Doll%20Envelopes/README.md) ### 回溯算法 -- [子集](/solution/0000-0099/0078.Subsets/README.md) -- [子集 II](/solution/0000-0099/0090.Subsets%20II/README.md) +- [子集](/solution/0000-0099/0078.Subsets/README.md) +- [子集 II](/solution/0000-0099/0090.Subsets%20II/README.md) ### 并查集 -- [被围绕的区域](/solution/0100-0199/0130.Surrounded%20Regions/README.md) -- [省份数量](/solution/0500-0599/0547.Number%20of%20Provinces/README.md) -- [冗余连接](/solution/0600-0699/0684.Redundant%20Connection/README.md) -- [可能的二分法](/solution/0800-0899/0886.Possible%20Bipartition/README.md) +- [被围绕的区域](/solution/0100-0199/0130.Surrounded%20Regions/README.md) +- [省份数量](/solution/0500-0599/0547.Number%20of%20Provinces/README.md) +- [冗余连接](/solution/0600-0699/0684.Redundant%20Connection/README.md) +- [可能的二分法](/solution/0800-0899/0886.Possible%20Bipartition/README.md) ### 设计 -- [LRU 缓存机制](/solution/0100-0199/0146.Lru%20Cache/README.md) -- [实现 Trie (前缀树)](/solution/0200-0299/0208.Implement%20Trie%20%28Prefix%20Tree%29/README.md) -- [实现 Trie (前缀树) II](/solution/1800-1899/1804.Implement%20Trie%20II%20%28Prefix%20Tree%29/README.md) -- [设计循环队列](/solution/0600-0699/0622.Design%20Circular%20Queue/README.md) -- [设计循环双端队列](/solution/0600-0699/0641.Design%20Circular%20Deque/README.md) -- [设计哈希集合](/solution/0700-0799/0705.Design%20HashSet/README.md) -- [设计哈希映射](/solution/0700-0799/0706.Design%20HashMap/README.md) +- [LRU 缓存机制](/solution/0100-0199/0146.Lru%20Cache/README.md) +- [实现 Trie (前缀树)](/solution/0200-0299/0208.Implement%20Trie%20%28Prefix%20Tree%29/README.md) +- [实现 Trie (前缀树) II](/solution/1800-1899/1804.Implement%20Trie%20II%20%28Prefix%20Tree%29/README.md) +- [设计循环队列](/solution/0600-0699/0622.Design%20Circular%20Queue/README.md) +- [设计循环双端队列](/solution/0600-0699/0641.Design%20Circular%20Deque/README.md) +- [设计哈希集合](/solution/0700-0799/0705.Design%20HashSet/README.md) +- [设计哈希映射](/solution/0700-0799/0706.Design%20HashMap/README.md) ## 维护者 -- [Yang Libin](https://github.com/yanglbme) -- [Mao Longlong](https://github.com/MaoLongLong) +- [Yang Libin](https://github.com/yanglbme) +- [Mao Longlong](https://github.com/MaoLongLong) ## 加入我们 diff --git a/README_EN.md b/README_EN.md index 76624afba9f1a..6126cbe97ba02 100644 --- a/README_EN.md +++ b/README_EN.md @@ -20,211 +20,211 @@ Complete solutions to [LeetCode](https://leetcode.com/problemset/all/), [LCOF](h ## Sites -- Netlify: https://lc.netlify.app -- GitHub Pages: https://doocs.github.io/leetcode +- Gitee Pages: https://doocs.gitee.io/leetcode +- GitHub Pages: https://doocs.github.io/leetcode ## Solutions -- [LeetCode](/solution/README_EN.md) -- [LCOF: Coding Interviews, 2nd Edition](/lcof/README_EN.md) -- [LCCI: Cracking the Coding Interview, 6th Edition](/lcci/README_EN.md) +- [LeetCode](/solution/README_EN.md) +- [LCOF: Coding Interviews, 2nd Edition](/lcof/README_EN.md) +- [LCCI: Cracking the Coding Interview, 6th Edition](/lcci/README_EN.md) ## Basic Algorithms ### Sorting -- [Bubble Sort](/basic/sorting/BubbleSort/README.md) -- [Insertion Sort](/basic/sorting/InsertionSort/README.md) -- [Selection Sort](/basic/sorting/SelectionSort/README.md) -- [Merge Sort(Algorithm Template)](/basic/sorting/MergeSort/README.md) -- [Quick Sort(Algorithm Template)](/basic/sorting/QuickSort/README.md) -- [Shell Sort](/basic/sorting/ShellSort/README.md) -- [Heap Sort(Algorithm Template)](/basic/sorting/HeapSort/README.md) +- [Bubble Sort](/basic/sorting/BubbleSort/README.md) +- [Insertion Sort](/basic/sorting/InsertionSort/README.md) +- [Selection Sort](/basic/sorting/SelectionSort/README.md) +- [Merge Sort(Algorithm Template)](/basic/sorting/MergeSort/README.md) +- [Quick Sort(Algorithm Template)](/basic/sorting/QuickSort/README.md) +- [Shell Sort](/basic/sorting/ShellSort/README.md) +- [Heap Sort(Algorithm Template)](/basic/sorting/HeapSort/README.md) ### Searching -- [Binary Search(Algorithm Template)](/basic/searching/BinarySearch/README_EN.md) +- [Binary Search(Algorithm Template)](/basic/searching/BinarySearch/README_EN.md) ## High Frequency Interview Questions ### Arrays -- [Majority Element](/solution/0100-0199/0169.Majority%20Element/README_EN.md) -- [Remove Duplicates from Sorted Array](/solution/0000-0099/0026.Remove%20Duplicates%20from%20Sorted%20Array/README_EN.md) -- [Remove Duplicates from Sorted Array II](/solution/0000-0099/0080.Remove%20Duplicates%20from%20Sorted%20Array%20II/README_EN.md) -- [Remove Element](/solution/0000-0099/0027.Remove%20Element/README_EN.md) -- [Move Zeroes](/solution/0200-0299/0283.Move%20Zeroes/README_EN.md) -- [Rotate Array](/solution/0100-0199/0189.Rotate%20Array/README_EN.md) -- [Spiral Matrix](/solution/0000-0099/0054.Spiral%20Matrix/README_EN.md) -- [Two Sum](/solution/0000-0099/0001.Two%20Sum/README_EN.md) -- [3Sum](/solution/0000-0099/0015.3Sum/README_EN.md) -- [4Sum](/solution/0000-0099/0018.4Sum/README_EN.md) -- [3Sum Smaller](/solution/0200-0299/0259.3Sum%20Smaller/README_EN.md) -- [3Sum Closest](/solution/0000-0099/0016.3Sum%20Closest/README_EN.md) -- [Merge Sorted Array](/solution/0000-0099/0088.Merge%20Sorted%20Array/README_EN.md) -- [Find Minimum in Rotated Sorted Array](/solution/0100-0199/0153.Find%20Minimum%20in%20Rotated%20Sorted%20Array/README_EN.md) -- [Find Minimum in Rotated Sorted Array II](/solution/0100-0199/0154.Find%20Minimum%20in%20Rotated%20Sorted%20Array%20II/README_EN.md) -- [Product of Array Except Self](/solution/0200-0299/0238.Product%20of%20Array%20Except%20Self/README_EN.md) +- [Majority Element](/solution/0100-0199/0169.Majority%20Element/README_EN.md) +- [Remove Duplicates from Sorted Array](/solution/0000-0099/0026.Remove%20Duplicates%20from%20Sorted%20Array/README_EN.md) +- [Remove Duplicates from Sorted Array II](/solution/0000-0099/0080.Remove%20Duplicates%20from%20Sorted%20Array%20II/README_EN.md) +- [Remove Element](/solution/0000-0099/0027.Remove%20Element/README_EN.md) +- [Move Zeroes](/solution/0200-0299/0283.Move%20Zeroes/README_EN.md) +- [Rotate Array](/solution/0100-0199/0189.Rotate%20Array/README_EN.md) +- [Spiral Matrix](/solution/0000-0099/0054.Spiral%20Matrix/README_EN.md) +- [Two Sum](/solution/0000-0099/0001.Two%20Sum/README_EN.md) +- [3Sum](/solution/0000-0099/0015.3Sum/README_EN.md) +- [4Sum](/solution/0000-0099/0018.4Sum/README_EN.md) +- [3Sum Smaller](/solution/0200-0299/0259.3Sum%20Smaller/README_EN.md) +- [3Sum Closest](/solution/0000-0099/0016.3Sum%20Closest/README_EN.md) +- [Merge Sorted Array](/solution/0000-0099/0088.Merge%20Sorted%20Array/README_EN.md) +- [Find Minimum in Rotated Sorted Array](/solution/0100-0199/0153.Find%20Minimum%20in%20Rotated%20Sorted%20Array/README_EN.md) +- [Find Minimum in Rotated Sorted Array II](/solution/0100-0199/0154.Find%20Minimum%20in%20Rotated%20Sorted%20Array%20II/README_EN.md) +- [Product of Array Except Self](/solution/0200-0299/0238.Product%20of%20Array%20Except%20Self/README_EN.md) ### Strings -- [Longest Substring Without Repeating Characters](/solution/0000-0099/0003.Longest%20Substring%20Without%20Repeating%20Characters/README_EN.md) -- [Longest Common Prefix](/solution/0000-0099/0014.Longest%20Common%20Prefix/README_EN.md) -- [Reverse Vowels of a String](/solution/0300-0399/0345.Reverse%20Vowels%20of%20a%20String/README_EN.md) -- [String to Integer (atoi)](/solution/0000-0099/0008.String%20to%20Integer%20%28atoi%29/README_EN.md) -- [Ransom Note](/solution/0300-0399/0383.Ransom%20Note/README_EN.md) +- [Longest Substring Without Repeating Characters](/solution/0000-0099/0003.Longest%20Substring%20Without%20Repeating%20Characters/README_EN.md) +- [Longest Common Prefix](/solution/0000-0099/0014.Longest%20Common%20Prefix/README_EN.md) +- [Reverse Vowels of a String](/solution/0300-0399/0345.Reverse%20Vowels%20of%20a%20String/README_EN.md) +- [String to Integer (atoi)](/solution/0000-0099/0008.String%20to%20Integer%20%28atoi%29/README_EN.md) +- [Ransom Note](/solution/0300-0399/0383.Ransom%20Note/README_EN.md) ### Linked List -- [Add Two Numbers](/solution/0000-0099/0002.Add%20Two%20Numbers/README_EN.md) -- [Add Two Numbers II](/solution/0400-0499/0445.Add%20Two%20Numbers%20II/README_EN.md) -- [Delete Node in a Linked List](/solution/0200-0299/0237.Delete%20Node%20in%20a%20Linked%20List/README_EN.md) -- [Remove Duplicates from Sorted List](/solution/0000-0099/0083.Remove%20Duplicates%20from%20Sorted%20List/README_EN.md) -- [Remove Duplicates from Sorted List II](/solution/0000-0099/0082.Remove%20Duplicates%20from%20Sorted%20List%20II/README_EN.md) -- [Remove Linked List Elements](/solution/0200-0299/0203.Remove%20Linked%20List%20Elements/README_EN.md) -- [Kth Node From End of List](/lcci/02.02.Kth%20Node%20From%20End%20of%20List/README_EN.md) -- [Swap Nodes in Pairs](/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/README_EN.md) -- [Merge Two Sorted Lists](/solution/0000-0099/0021.Merge%20Two%20Sorted%20Lists/README_EN.md) -- [Merge k Sorted Lists](/solution/0000-0099/0023.Merge%20k%20Sorted%20Lists/README_EN.md) -- [Insertion Sort List](/solution/0100-0199/0147.Insertion%20Sort%20List/README_EN.md) -- [Sort List](/solution/0100-0199/0148.Sort%20List/README_EN.md) -- [Reverse Linked List](/solution/0200-0299/0206.Reverse%20Linked%20List/README_EN.md) -- [Reverse Linked List II](/solution/0000-0099/0092.Reverse%20Linked%20List%20II/README_EN.md) -- [Reorder List](/solution/0100-0199/0143.Reorder%20List/README_EN.md) -- [Rotate List](/solution/0000-0099/0061.Rotate%20List/README_EN.md) -- [Palindrome Linked List](/solution/0200-0299/0234.Palindrome%20Linked%20List/README_EN.md) -- [Intersection of Two Linked Lists](/solution/0100-0199/0160.Intersection%20of%20Two%20Linked%20Lists/README_EN.md) -- [Odd Even Linked List](/solution/0300-0399/0328.Odd%20Even%20Linked%20List/README_EN.md) -- [Linked List Cycle](/solution/0100-0199/0141.Linked%20List%20Cycle/README_EN.md) -- [Linked List Cycle II](/solution/0100-0199/0142.Linked%20List%20Cycle%20II/README_EN.md) -- [Design Linked List](/solution/0700-0799/0707.Design%20Linked%20List/README_EN.md) +- [Add Two Numbers](/solution/0000-0099/0002.Add%20Two%20Numbers/README_EN.md) +- [Add Two Numbers II](/solution/0400-0499/0445.Add%20Two%20Numbers%20II/README_EN.md) +- [Delete Node in a Linked List](/solution/0200-0299/0237.Delete%20Node%20in%20a%20Linked%20List/README_EN.md) +- [Remove Duplicates from Sorted List](/solution/0000-0099/0083.Remove%20Duplicates%20from%20Sorted%20List/README_EN.md) +- [Remove Duplicates from Sorted List II](/solution/0000-0099/0082.Remove%20Duplicates%20from%20Sorted%20List%20II/README_EN.md) +- [Remove Linked List Elements](/solution/0200-0299/0203.Remove%20Linked%20List%20Elements/README_EN.md) +- [Kth Node From End of List](/lcci/02.02.Kth%20Node%20From%20End%20of%20List/README_EN.md) +- [Swap Nodes in Pairs](/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/README_EN.md) +- [Merge Two Sorted Lists](/solution/0000-0099/0021.Merge%20Two%20Sorted%20Lists/README_EN.md) +- [Merge k Sorted Lists](/solution/0000-0099/0023.Merge%20k%20Sorted%20Lists/README_EN.md) +- [Insertion Sort List](/solution/0100-0199/0147.Insertion%20Sort%20List/README_EN.md) +- [Sort List](/solution/0100-0199/0148.Sort%20List/README_EN.md) +- [Reverse Linked List](/solution/0200-0299/0206.Reverse%20Linked%20List/README_EN.md) +- [Reverse Linked List II](/solution/0000-0099/0092.Reverse%20Linked%20List%20II/README_EN.md) +- [Reorder List](/solution/0100-0199/0143.Reorder%20List/README_EN.md) +- [Rotate List](/solution/0000-0099/0061.Rotate%20List/README_EN.md) +- [Palindrome Linked List](/solution/0200-0299/0234.Palindrome%20Linked%20List/README_EN.md) +- [Intersection of Two Linked Lists](/solution/0100-0199/0160.Intersection%20of%20Two%20Linked%20Lists/README_EN.md) +- [Odd Even Linked List](/solution/0300-0399/0328.Odd%20Even%20Linked%20List/README_EN.md) +- [Linked List Cycle](/solution/0100-0199/0141.Linked%20List%20Cycle/README_EN.md) +- [Linked List Cycle II](/solution/0100-0199/0142.Linked%20List%20Cycle%20II/README_EN.md) +- [Design Linked List](/solution/0700-0799/0707.Design%20Linked%20List/README_EN.md) ### Binary Tree -- [Binary Tree Preorder Traversal](/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/README_EN.md) -- [Binary Tree Postorder Traversal](/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/README_EN.md) -- [Binary Tree Inorder Traversal](/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/README_EN.md) -- [Symmetric Tree](/solution/0100-0199/0101.Symmetric%20Tree/README_EN.md) -- [Invert Binary Tree](/solution/0200-0299/0226.Invert%20Binary%20Tree/README_EN.md) -- [Binary Tree Level Order Traversal](/solution/0100-0199/0102.Binary%20Tree%20Level%20Order%20Traversal/README_EN.md) -- [Binary Tree Level Order Traversal II](/solution/0100-0199/0107.Binary%20Tree%20Level%20Order%20Traversal%20II/README_EN.md) -- [Binary Tree Right Side View](/solution/0100-0199/0199.Binary%20Tree%20Right%20Side%20View/README_EN.md) -- [Maximum Depth of Binary Tree](/solution/0100-0199/0104.Maximum%20Depth%20of%20Binary%20Tree/README_EN.md) -- [Minimum Depth of Binary Tree](/solution/0100-0199/0111.Minimum%20Depth%20of%20Binary%20Tree/README_EN.md) -- [Binary Tree Paths](/solution/0200-0299/0257.Binary%20Tree%20Paths/README_EN.md) -- [Path Sum](/solution/0100-0199/0112.Path%20Sum/README_EN.md) -- [Path Sum II](/solution/0100-0199/0113.Path%20Sum%20II/README_EN.md) -- [Construct Binary Tree from Preorder and Inorder Traversal](/solution/0100-0199/0105.Construct%20Binary%20Tree%20from%20Preorder%20and%20Inorder%20Traversal/README_EN.md) -- [Construct Binary Tree from Inorder and Postorder Traversal](/solution/0100-0199/0106.Construct%20Binary%20Tree%20from%20Inorder%20and%20Postorder%20Traversal/README_EN.md) -- [Binary Search Tree Iterator](/solution/0100-0199/0173.Binary%20Search%20Tree%20Iterator/README_EN.md) -- [Lowest Common Ancestor of a Binary Tree](/solution/0200-0299/0236.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree/README_EN.md) -- [Lowest Common Ancestor of a Binary Search Tree](/solution/0200-0299/0235.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Search%20Tree/README_EN.md) -- [BiNode](/lcci/17.12.BiNode/README_EN.md) -- [Convert Binary Search Tree to Sorted Doubly Linked List](/solution/0400-0499/0426.Convert%20Binary%20Search%20Tree%20to%20Sorted%20Doubly%20Linked%20List/README_EN.md) -- [Boundary of Binary Tree](/solution/0500-0599/0545.Boundary%20of%20Binary%20Tree/README_EN.md) -- [Populating Next Right Pointers in Each Node](/solution/0100-0199/0116.Populating%20Next%20Right%20Pointers%20in%20Each%20Node/README_EN.md) -- [Populating Next Right Pointers in Each Node II](/solution/0100-0199/0117.Populating%20Next%20Right%20Pointers%20in%20Each%20Node%20II/README_EN.md) +- [Binary Tree Preorder Traversal](/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/README_EN.md) +- [Binary Tree Postorder Traversal](/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/README_EN.md) +- [Binary Tree Inorder Traversal](/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/README_EN.md) +- [Symmetric Tree](/solution/0100-0199/0101.Symmetric%20Tree/README_EN.md) +- [Invert Binary Tree](/solution/0200-0299/0226.Invert%20Binary%20Tree/README_EN.md) +- [Binary Tree Level Order Traversal](/solution/0100-0199/0102.Binary%20Tree%20Level%20Order%20Traversal/README_EN.md) +- [Binary Tree Level Order Traversal II](/solution/0100-0199/0107.Binary%20Tree%20Level%20Order%20Traversal%20II/README_EN.md) +- [Binary Tree Right Side View](/solution/0100-0199/0199.Binary%20Tree%20Right%20Side%20View/README_EN.md) +- [Maximum Depth of Binary Tree](/solution/0100-0199/0104.Maximum%20Depth%20of%20Binary%20Tree/README_EN.md) +- [Minimum Depth of Binary Tree](/solution/0100-0199/0111.Minimum%20Depth%20of%20Binary%20Tree/README_EN.md) +- [Binary Tree Paths](/solution/0200-0299/0257.Binary%20Tree%20Paths/README_EN.md) +- [Path Sum](/solution/0100-0199/0112.Path%20Sum/README_EN.md) +- [Path Sum II](/solution/0100-0199/0113.Path%20Sum%20II/README_EN.md) +- [Construct Binary Tree from Preorder and Inorder Traversal](/solution/0100-0199/0105.Construct%20Binary%20Tree%20from%20Preorder%20and%20Inorder%20Traversal/README_EN.md) +- [Construct Binary Tree from Inorder and Postorder Traversal](/solution/0100-0199/0106.Construct%20Binary%20Tree%20from%20Inorder%20and%20Postorder%20Traversal/README_EN.md) +- [Binary Search Tree Iterator](/solution/0100-0199/0173.Binary%20Search%20Tree%20Iterator/README_EN.md) +- [Lowest Common Ancestor of a Binary Tree](/solution/0200-0299/0236.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree/README_EN.md) +- [Lowest Common Ancestor of a Binary Search Tree](/solution/0200-0299/0235.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Search%20Tree/README_EN.md) +- [BiNode](/lcci/17.12.BiNode/README_EN.md) +- [Convert Binary Search Tree to Sorted Doubly Linked List](/solution/0400-0499/0426.Convert%20Binary%20Search%20Tree%20to%20Sorted%20Doubly%20Linked%20List/README_EN.md) +- [Boundary of Binary Tree](/solution/0500-0599/0545.Boundary%20of%20Binary%20Tree/README_EN.md) +- [Populating Next Right Pointers in Each Node](/solution/0100-0199/0116.Populating%20Next%20Right%20Pointers%20in%20Each%20Node/README_EN.md) +- [Populating Next Right Pointers in Each Node II](/solution/0100-0199/0117.Populating%20Next%20Right%20Pointers%20in%20Each%20Node%20II/README_EN.md) ### Math -- [Integer to Roman](/solution/0000-0099/0012.Integer%20to%20Roman/README_EN.md) -- [Roman to Integer](/solution/0000-0099/0013.Roman%20to%20Integer/README_EN.md) -- [Single Number](/solution/0100-0199/0136.Single%20Number/README_EN.md) -- [Single Number II](/solution/0100-0199/0137.Single%20Number%20II/README_EN.md) -- [Single Number III](/solution/0200-0299/0260.Single%20Number%20III/README_EN.md) -- [Set Mismatch](/solution/0600-0699/0645.Set%20Mismatch/README_EN.md) -- [Number of 1 Bits](/solution/0100-0199/0191.Number%20of%201%20Bits/README_EN.md) -- [Count Primes](/solution/0200-0299/0204.Count%20Primes/README_EN.md) -- [Missing Number](/solution/0200-0299/0268.Missing%20Number/README_EN.md) +- [Integer to Roman](/solution/0000-0099/0012.Integer%20to%20Roman/README_EN.md) +- [Roman to Integer](/solution/0000-0099/0013.Roman%20to%20Integer/README_EN.md) +- [Single Number](/solution/0100-0199/0136.Single%20Number/README_EN.md) +- [Single Number II](/solution/0100-0199/0137.Single%20Number%20II/README_EN.md) +- [Single Number III](/solution/0200-0299/0260.Single%20Number%20III/README_EN.md) +- [Set Mismatch](/solution/0600-0699/0645.Set%20Mismatch/README_EN.md) +- [Number of 1 Bits](/solution/0100-0199/0191.Number%20of%201%20Bits/README_EN.md) +- [Count Primes](/solution/0200-0299/0204.Count%20Primes/README_EN.md) +- [Missing Number](/solution/0200-0299/0268.Missing%20Number/README_EN.md) ### Stack & Queue -- [Valid Parentheses](/solution/0000-0099/0020.Valid%20Parentheses/README_EN.md) -- [Min Stack](/solution/0100-0199/0155.Min%20Stack/README_EN.md) -- [Implement Queue using Stacks](/solution/0200-0299/0232.Implement%20Queue%20using%20Stacks/README_EN.md) -- [Implement Stack using Queues](/solution/0200-0299/0225.Implement%20Stack%20using%20Queues/README_EN.md) -- [Evaluate Reverse Polish Notation](/solution/0100-0199/0150.Evaluate%20Reverse%20Polish%20Notation/README_EN.md) -- [Number of Recent Calls](/solution/0900-0999/0933.Number%20of%20Recent%20Calls/README_EN.md) -- [Daily Temperatures](/solution/0700-0799/0739.Daily%20Temperatures/README_EN.md) -- [Basic Calculator II](/solution/0200-0299/0227.Basic%20Calculator%20II/README_EN.md) -- [Next Greater Element I](/solution/0400-0499/0496.Next%20Greater%20Element%20I/README_EN.md) -- [Next Greater Element II](/solution/0500-0599/0503.Next%20Greater%20Element%20II/README_EN.md) +- [Valid Parentheses](/solution/0000-0099/0020.Valid%20Parentheses/README_EN.md) +- [Min Stack](/solution/0100-0199/0155.Min%20Stack/README_EN.md) +- [Implement Queue using Stacks](/solution/0200-0299/0232.Implement%20Queue%20using%20Stacks/README_EN.md) +- [Implement Stack using Queues](/solution/0200-0299/0225.Implement%20Stack%20using%20Queues/README_EN.md) +- [Evaluate Reverse Polish Notation](/solution/0100-0199/0150.Evaluate%20Reverse%20Polish%20Notation/README_EN.md) +- [Number of Recent Calls](/solution/0900-0999/0933.Number%20of%20Recent%20Calls/README_EN.md) +- [Daily Temperatures](/solution/0700-0799/0739.Daily%20Temperatures/README_EN.md) +- [Basic Calculator II](/solution/0200-0299/0227.Basic%20Calculator%20II/README_EN.md) +- [Next Greater Element I](/solution/0400-0499/0496.Next%20Greater%20Element%20I/README_EN.md) +- [Next Greater Element II](/solution/0500-0599/0503.Next%20Greater%20Element%20II/README_EN.md) ### Dynamic Programming -- [Fibonacci Number](/solution/0500-0599/0509.Fibonacci%20Number/README_EN.md) -- [N-th Tribonacci Number](/solution/1100-1199/1137.N-th%20Tribonacci%20Number/README_EN.md) -- [Climbing Stairs](/solution/0000-0099/0070.Climbing%20Stairs/README_EN.md) -- [Min Cost Climbing Stairs](/solution/0700-0799/0746.Min%20Cost%20Climbing%20Stairs/README_EN.md) -- [House Robber](/solution/0100-0199/0198.House%20Robber/README_EN.md) -- [House Robber II](/solution/0200-0299/0213.House%20Robber%20II/README_EN.md) -- [Delete and Earn](/solution/0700-0799/0740.Delete%20and%20Earn/README_EN.md) -- [Jump Game](/solution/0000-0099/0055.Jump%20Game/README_EN.md) -- [Jump Game II](/solution/0000-0099/0045.Jump%20Game%20II/README_EN.md) -- [Maximum Subarray](/solution/0000-0099/0053.Maximum%20Subarray/README_EN.md) -- [Maximum Sum Circular Subarray](/solution/0900-0999/0918.Maximum%20Sum%20Circular%20Subarray/README_EN.md) -- [Maximum Product Subarray](/solution/0100-0199/0152.Maximum%20Product%20Subarray/README_EN.md) -- [Maximum Length of Subarray With Positive Product](/solution/1500-1599/1567.Maximum%20Length%20of%20Subarray%20With%20Positive%20Product/README_EN.md) -- [Best Sightseeing Pair](/solution/1000-1099/1014.Best%20Sightseeing%20Pair/README_EN.md) -- [Best Time to Buy and Sell Stock](/solution/0100-0199/0121.Best%20Time%20to%20Buy%20and%20Sell%20Stock/README_EN.md) -- [Best Time to Buy and Sell Stock II](/solution/0100-0199/0122.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II/README_EN.md) -- [Best Time to Buy and Sell Stock III](/solution/0100-0199/0123.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20III/README_EN.md) -- [Best Time to Buy and Sell Stock with Cooldown](/solution/0300-0399/0309.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Cooldown/README_EN.md) -- [Best Time to Buy and Sell Stock with Transaction Fee](/solution/0700-0799/0714.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Transaction%20Fee/README_EN.md) -- [Word Break](/solution/0100-0199/0139.Word%20Break/README_EN.md) -- [Trapping Rain Water](/solution/0000-0099/0042.Trapping%20Rain%20Water/README_EN.md) -- [Arithmetic Slices](/solution/0400-0499/0413.Arithmetic%20Slices/README_EN.md) -- [Decode Ways](/solution/0000-0099/0091.Decode%20Ways/README_EN.md) -- [Unique Binary Search Trees](/solution/0000-0099/0096.Unique%20Binary%20Search%20Trees/README_EN.md) -- [Ugly Number II](/solution/0200-0299/0264.Ugly%20Number%20II/README_EN.md) -- [Pascal's Triangle](/solution/0100-0199/0118.Pascal%27s%20Triangle/README_EN.md) -- [Pascal's Triangle II](/solution/0100-0199/0119.Pascal%27s%20Triangle%20II/README_EN.md) -- [Minimum Falling Path Sum](/solution/0900-0999/0931.Minimum%20Falling%20Path%20Sum/README_EN.md) -- [Triangle](/solution/0100-0199/0120.Triangle/README_EN.md) -- [Matrix Block Sum](/solution/1300-1399/1314.Matrix%20Block%20Sum/README_EN.md) -- [Range Sum Query 2D - Immutable](/solution/0300-0399/0304.Range%20Sum%20Query%202D%20-%20Immutable/README_EN.md) -- [Unique Paths](/solution/0000-0099/0062.Unique%20Paths/README_EN.md) -- [Unique Paths II](/solution/0000-0099/0063.Unique%20Paths%20II/README_EN.md) -- [Minimum Path Sum](/solution/0000-0099/0064.Minimum%20Path%20Sum/README_EN.md) -- [Longest Palindromic Substring](/solution/0000-0099/0005.Longest%20Palindromic%20Substring/README_EN.md) -- [Longest Palindromic Subsequence](.solution/0500-0599/0516.Longest%20Palindromic%20Subsequence/README_EN.md) -- [Longest Increasing Subsequence](/solution/0300-0399/0300.Longest%20Increasing%20Subsequence/README_EN.md) -- [Wiggle Subsequence](/solution/0300-0399/0376.Wiggle%20Subsequence/README_EN.md) -- [Longest Common Subsequence](/solution/1100-1199/1143.Longest%20Common%20Subsequence/README_EN.md) -- [Edit Distance](/solution/0000-0099/0072.Edit%20Distance/README_EN.md) -- [Coin Change](/solution/0300-0399/0322.Coin%20Change/README_EN.md) -- [Coin Change 2](/solution/0500-0599/0518.Coin%20Change%202/README_EN.md) -- [Combination Sum IV](/solution/0300-0399/0377.Combination%20Sum%20IV/README_EN.md) -- [Integer Break](/solution/0300-0399/0343.Integer%20Break/README_EN.md) -- [Perfect Squares](/solution/0200-0299/0279.Perfect%20Squares/README_EN.md) -- [Russian Doll Envelopes](/solution/0300-0399/0354.Russian%20Doll%20Envelopes/README_EN.md) +- [Fibonacci Number](/solution/0500-0599/0509.Fibonacci%20Number/README_EN.md) +- [N-th Tribonacci Number](/solution/1100-1199/1137.N-th%20Tribonacci%20Number/README_EN.md) +- [Climbing Stairs](/solution/0000-0099/0070.Climbing%20Stairs/README_EN.md) +- [Min Cost Climbing Stairs](/solution/0700-0799/0746.Min%20Cost%20Climbing%20Stairs/README_EN.md) +- [House Robber](/solution/0100-0199/0198.House%20Robber/README_EN.md) +- [House Robber II](/solution/0200-0299/0213.House%20Robber%20II/README_EN.md) +- [Delete and Earn](/solution/0700-0799/0740.Delete%20and%20Earn/README_EN.md) +- [Jump Game](/solution/0000-0099/0055.Jump%20Game/README_EN.md) +- [Jump Game II](/solution/0000-0099/0045.Jump%20Game%20II/README_EN.md) +- [Maximum Subarray](/solution/0000-0099/0053.Maximum%20Subarray/README_EN.md) +- [Maximum Sum Circular Subarray](/solution/0900-0999/0918.Maximum%20Sum%20Circular%20Subarray/README_EN.md) +- [Maximum Product Subarray](/solution/0100-0199/0152.Maximum%20Product%20Subarray/README_EN.md) +- [Maximum Length of Subarray With Positive Product](/solution/1500-1599/1567.Maximum%20Length%20of%20Subarray%20With%20Positive%20Product/README_EN.md) +- [Best Sightseeing Pair](/solution/1000-1099/1014.Best%20Sightseeing%20Pair/README_EN.md) +- [Best Time to Buy and Sell Stock](/solution/0100-0199/0121.Best%20Time%20to%20Buy%20and%20Sell%20Stock/README_EN.md) +- [Best Time to Buy and Sell Stock II](/solution/0100-0199/0122.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II/README_EN.md) +- [Best Time to Buy and Sell Stock III](/solution/0100-0199/0123.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20III/README_EN.md) +- [Best Time to Buy and Sell Stock with Cooldown](/solution/0300-0399/0309.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Cooldown/README_EN.md) +- [Best Time to Buy and Sell Stock with Transaction Fee](/solution/0700-0799/0714.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Transaction%20Fee/README_EN.md) +- [Word Break](/solution/0100-0199/0139.Word%20Break/README_EN.md) +- [Trapping Rain Water](/solution/0000-0099/0042.Trapping%20Rain%20Water/README_EN.md) +- [Arithmetic Slices](/solution/0400-0499/0413.Arithmetic%20Slices/README_EN.md) +- [Decode Ways](/solution/0000-0099/0091.Decode%20Ways/README_EN.md) +- [Unique Binary Search Trees](/solution/0000-0099/0096.Unique%20Binary%20Search%20Trees/README_EN.md) +- [Ugly Number II](/solution/0200-0299/0264.Ugly%20Number%20II/README_EN.md) +- [Pascal's Triangle](/solution/0100-0199/0118.Pascal%27s%20Triangle/README_EN.md) +- [Pascal's Triangle II](/solution/0100-0199/0119.Pascal%27s%20Triangle%20II/README_EN.md) +- [Minimum Falling Path Sum](/solution/0900-0999/0931.Minimum%20Falling%20Path%20Sum/README_EN.md) +- [Triangle](/solution/0100-0199/0120.Triangle/README_EN.md) +- [Matrix Block Sum](/solution/1300-1399/1314.Matrix%20Block%20Sum/README_EN.md) +- [Range Sum Query 2D - Immutable](/solution/0300-0399/0304.Range%20Sum%20Query%202D%20-%20Immutable/README_EN.md) +- [Unique Paths](/solution/0000-0099/0062.Unique%20Paths/README_EN.md) +- [Unique Paths II](/solution/0000-0099/0063.Unique%20Paths%20II/README_EN.md) +- [Minimum Path Sum](/solution/0000-0099/0064.Minimum%20Path%20Sum/README_EN.md) +- [Longest Palindromic Substring](/solution/0000-0099/0005.Longest%20Palindromic%20Substring/README_EN.md) +- [Longest Palindromic Subsequence](.solution/0500-0599/0516.Longest%20Palindromic%20Subsequence/README_EN.md) +- [Longest Increasing Subsequence](/solution/0300-0399/0300.Longest%20Increasing%20Subsequence/README_EN.md) +- [Wiggle Subsequence](/solution/0300-0399/0376.Wiggle%20Subsequence/README_EN.md) +- [Longest Common Subsequence](/solution/1100-1199/1143.Longest%20Common%20Subsequence/README_EN.md) +- [Edit Distance](/solution/0000-0099/0072.Edit%20Distance/README_EN.md) +- [Coin Change](/solution/0300-0399/0322.Coin%20Change/README_EN.md) +- [Coin Change 2](/solution/0500-0599/0518.Coin%20Change%202/README_EN.md) +- [Combination Sum IV](/solution/0300-0399/0377.Combination%20Sum%20IV/README_EN.md) +- [Integer Break](/solution/0300-0399/0343.Integer%20Break/README_EN.md) +- [Perfect Squares](/solution/0200-0299/0279.Perfect%20Squares/README_EN.md) +- [Russian Doll Envelopes](/solution/0300-0399/0354.Russian%20Doll%20Envelopes/README_EN.md) ### Backtracking -- [Subsets](/solution/0000-0099/0078.Subsets/README_EN.md) -- [Subsets II](/solution/0000-0099/0090.Subsets%20II/README_EN.md) +- [Subsets](/solution/0000-0099/0078.Subsets/README_EN.md) +- [Subsets II](/solution/0000-0099/0090.Subsets%20II/README_EN.md) ### Union Find -- [Surrounded Regions](/solution/0100-0199/0130.Surrounded%20Regions/README_EN.md) -- [Number of Provinces](/solution/0500-0599/0547.Number%20of%20Provinces/README_EN.md) -- [Redundant Connection](/solution/0600-0699/0684.Redundant%20Connection/README_EN.md) -- [Possible Bipartition](/solution/0800-0899/0886.Possible%20Bipartition/README_EN.md) +- [Surrounded Regions](/solution/0100-0199/0130.Surrounded%20Regions/README_EN.md) +- [Number of Provinces](/solution/0500-0599/0547.Number%20of%20Provinces/README_EN.md) +- [Redundant Connection](/solution/0600-0699/0684.Redundant%20Connection/README_EN.md) +- [Possible Bipartition](/solution/0800-0899/0886.Possible%20Bipartition/README_EN.md) ### Design -- [LRU Cache](/solution/0100-0199/0146.Lru%20Cache/README_EN.md) -- [Implement Trie (Prefix Tree)](/solution/0200-0299/0208.Implement%20Trie%20%28Prefix%20Tree%29/README_EN.md) -- [Implement Trie II (Prefix Tree)](/solution/1800-1899/1804.Implement%20Trie%20II%20%28Prefix%20Tree%29/README_EN.md) -- [Design Circular Queue](/solution/0600-0699/0622.Design%20Circular%20Queue/README_EN.md) -- [Design Circular Deque](/solution/0600-0699/0641.Design%20Circular%20Deque/README_EN.md) -- [Design HashSet](/solution/0700-0799/0705.Design%20HashSet/README_EN.md) -- [Design HashMap](/solution/0700-0799/0706.Design%20HashMap/README_EN.md) +- [LRU Cache](/solution/0100-0199/0146.Lru%20Cache/README_EN.md) +- [Implement Trie (Prefix Tree)](/solution/0200-0299/0208.Implement%20Trie%20%28Prefix%20Tree%29/README_EN.md) +- [Implement Trie II (Prefix Tree)](/solution/1800-1899/1804.Implement%20Trie%20II%20%28Prefix%20Tree%29/README_EN.md) +- [Design Circular Queue](/solution/0600-0699/0622.Design%20Circular%20Queue/README_EN.md) +- [Design Circular Deque](/solution/0600-0699/0641.Design%20Circular%20Deque/README_EN.md) +- [Design HashSet](/solution/0700-0799/0705.Design%20HashSet/README_EN.md) +- [Design HashMap](/solution/0700-0799/0706.Design%20HashMap/README_EN.md) ## Maintainers -- [Yang Libin](https://github.com/yanglbme) -- [Mao Longlong](https://github.com/MaoLongLong) +- [Yang Libin](https://github.com/yanglbme) +- [Mao Longlong](https://github.com/MaoLongLong) ## Contributions diff --git a/solution/1200-1299/1219.Path with Maximum Gold/README.md b/solution/1200-1299/1219.Path with Maximum Gold/README.md index a5f4c458602b0..d8de03caf1e6c 100644 --- a/solution/1200-1299/1219.Path with Maximum Gold/README.md +++ b/solution/1200-1299/1219.Path with Maximum Gold/README.md @@ -58,7 +58,9 @@ -DFS。 +枚举每个单元格作为起点,进行 DFS 搜索,找到收益最大的一条路径。 + +由于每个单元格只能被开采一次,因此当搜索到单元格 `(i, j)` 时,可以将 `grid[i][j]` 置为 0,搜索结束后再恢复 `grid[i][j]` 为原来的值。 @@ -70,22 +72,17 @@ DFS。 class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: def dfs(i, j): - if not (0 <= i < m and 0 <= j < n and grid[i][j]): + if not(0 <= i < m and 0 <= j < n and grid[i][j]): return 0 t = grid[i][j] grid[i][j] = 0 - res = 0 - for a, b in [[0, -1], [0, 1], [1, 0], [-1, 0]]: - res = max(res, t + dfs(i + a, j + b)) + ans = t + max(dfs(i + a, j + b) + for a, b in [[0, 1], [0, -1], [-1, 0], [1, 0]]) grid[i][j] = t - return res + return ans m, n = len(grid), len(grid[0]) - ans = 0 - for i in range(m): - for j in range(n): - ans = max(ans, dfs(i, j)) - return ans + return max(dfs(i, j) for i in range(m) for j in range(n)) ``` ### **Java** @@ -95,12 +92,16 @@ class Solution: ```java class Solution { private int[][] grid; + private int m; + private int n; public int getMaximumGold(int[][] grid) { + m = grid.length; + n = grid[0].length; this.grid = grid; int ans = 0; - for (int i = 0; i < grid.length; ++i) { - for (int j = 0; j < grid[0].length; ++j) { + for (int i = 0; i < m; ++i) { + for (int j = 0; j < n; ++j) { ans = Math.max(ans, dfs(i, j)); } } @@ -108,18 +109,18 @@ class Solution { } private int dfs(int i, int j) { - if (i < 0 || i >= grid.length || j < 0 || j >= grid[0].length || grid[i][j] == 0) { + if (i < 0 || i >= m || j < 0 || j >= n || grid[i][j] == 0) { return 0; } int t = grid[i][j]; grid[i][j] = 0; int[] dirs = {-1, 0, 1, 0, -1}; - int res = 0; + int ans = 0; for (int k = 0; k < 4; ++k) { - res = Math.max(res, t + dfs(i + dirs[k], j + dirs[k + 1])); + ans = Math.max(ans, t + dfs(i + dirs[k], j + dirs[k + 1])); } grid[i][j] = t; - return res; + return ans; } } ``` @@ -129,26 +130,24 @@ class Solution { ```cpp class Solution { public: - vector> grid; vector dirs = {-1, 0, 1, 0, -1}; int getMaximumGold(vector>& grid) { - this->grid = grid; int ans = 0; for (int i = 0; i < grid.size(); ++i) for (int j = 0; j < grid[0].size(); ++j) - ans = max(ans, dfs(i, j)); + ans = max(ans, dfs(i, j, grid)); return ans; } - int dfs(int i, int j) { + int dfs(int i, int j, vector>& grid) { if (i < 0 || i >= grid.size() || j < 0 || j >= grid[0].size() || grid[i][j] == 0) return 0; int t = grid[i][j]; grid[i][j] = 0; - int res = 0; - for (int k = 0; k < 4; ++k) res = max(res, t + dfs(i + dirs[k], j + dirs[k + 1])); + int ans = 0; + for (int k = 0; k < 4; ++k) ans = max(ans, t + dfs(i + dirs[k], j + dirs[k + 1], grid)); grid[i][j] = t; - return res; + return ans; } }; ``` @@ -165,13 +164,13 @@ func getMaximumGold(grid [][]int) int { } t := grid[i][j] grid[i][j] = 0 - res := 0 + ans := 0 dirs := []int{-1, 0, 1, 0, -1} for k := 0; k < 4; k++ { - res = max(res, t+dfs(i+dirs[k], j+dirs[k+1])) + ans = max(ans, t+dfs(i+dirs[k], j+dirs[k+1])) } grid[i][j] = t - return res + return ans } ans := 0 for i := 0; i < m; i++ { @@ -190,6 +189,40 @@ func max(a, b int) int { } ``` +### **JavaScript** + +```js +/** + * @param {number[][]} grid + * @return {number} + */ +var getMaximumGold = function (grid) { + const m = grid.length; + const n = grid[0].length; + function dfs(i, j) { + if (i < 0 || i >= m || j < 0 || j >= n || grid[i][j] == 0) { + return 0; + } + const t = grid[i][j]; + grid[i][j] = 0; + let ans = 0; + const dirs = [-1, 0, 1, 0, -1]; + for (let k = 0; k < 4; ++k) { + ans = Math.max(ans, t + dfs(i + dirs[k], j + dirs[k + 1])); + } + grid[i][j] = t; + return ans; + } + let ans = 0; + for (let i = 0; i < m; ++i) { + for (let j = 0; j < n; ++j) { + ans = Math.max(ans, dfs(i, j)); + } + } + return ans; +}; +``` + ### **...** ``` diff --git a/solution/1200-1299/1219.Path with Maximum Gold/README_EN.md b/solution/1200-1299/1219.Path with Maximum Gold/README_EN.md index 75a3fcebbcb43..7656887d54de2 100644 --- a/solution/1200-1299/1219.Path with Maximum Gold/README_EN.md +++ b/solution/1200-1299/1219.Path with Maximum Gold/README_EN.md @@ -66,22 +66,17 @@ DFS. class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: def dfs(i, j): - if not (0 <= i < m and 0 <= j < n and grid[i][j]): + if not(0 <= i < m and 0 <= j < n and grid[i][j]): return 0 t = grid[i][j] grid[i][j] = 0 - res = 0 - for a, b in [[0, -1], [0, 1], [1, 0], [-1, 0]]: - res = max(res, t + dfs(i + a, j + b)) + ans = t + max(dfs(i + a, j + b) + for a, b in [[0, 1], [0, -1], [-1, 0], [1, 0]]) grid[i][j] = t - return res + return ans m, n = len(grid), len(grid[0]) - ans = 0 - for i in range(m): - for j in range(n): - ans = max(ans, dfs(i, j)) - return ans + return max(dfs(i, j) for i in range(m) for j in range(n)) ``` ### **Java** @@ -89,12 +84,16 @@ class Solution: ```java class Solution { private int[][] grid; + private int m; + private int n; public int getMaximumGold(int[][] grid) { + m = grid.length; + n = grid[0].length; this.grid = grid; int ans = 0; - for (int i = 0; i < grid.length; ++i) { - for (int j = 0; j < grid[0].length; ++j) { + for (int i = 0; i < m; ++i) { + for (int j = 0; j < n; ++j) { ans = Math.max(ans, dfs(i, j)); } } @@ -102,18 +101,18 @@ class Solution { } private int dfs(int i, int j) { - if (i < 0 || i >= grid.length || j < 0 || j >= grid[0].length || grid[i][j] == 0) { + if (i < 0 || i >= m || j < 0 || j >= n || grid[i][j] == 0) { return 0; } int t = grid[i][j]; grid[i][j] = 0; int[] dirs = {-1, 0, 1, 0, -1}; - int res = 0; + int ans = 0; for (int k = 0; k < 4; ++k) { - res = Math.max(res, t + dfs(i + dirs[k], j + dirs[k + 1])); + ans = Math.max(ans, t + dfs(i + dirs[k], j + dirs[k + 1])); } grid[i][j] = t; - return res; + return ans; } } ``` @@ -123,26 +122,24 @@ class Solution { ```cpp class Solution { public: - vector> grid; vector dirs = {-1, 0, 1, 0, -1}; int getMaximumGold(vector>& grid) { - this->grid = grid; int ans = 0; for (int i = 0; i < grid.size(); ++i) for (int j = 0; j < grid[0].size(); ++j) - ans = max(ans, dfs(i, j)); + ans = max(ans, dfs(i, j, grid)); return ans; } - int dfs(int i, int j) { + int dfs(int i, int j, vector>& grid) { if (i < 0 || i >= grid.size() || j < 0 || j >= grid[0].size() || grid[i][j] == 0) return 0; int t = grid[i][j]; grid[i][j] = 0; - int res = 0; - for (int k = 0; k < 4; ++k) res = max(res, t + dfs(i + dirs[k], j + dirs[k + 1])); + int ans = 0; + for (int k = 0; k < 4; ++k) ans = max(ans, t + dfs(i + dirs[k], j + dirs[k + 1], grid)); grid[i][j] = t; - return res; + return ans; } }; ``` @@ -159,13 +156,13 @@ func getMaximumGold(grid [][]int) int { } t := grid[i][j] grid[i][j] = 0 - res := 0 + ans := 0 dirs := []int{-1, 0, 1, 0, -1} for k := 0; k < 4; k++ { - res = max(res, t+dfs(i+dirs[k], j+dirs[k+1])) + ans = max(ans, t+dfs(i+dirs[k], j+dirs[k+1])) } grid[i][j] = t - return res + return ans } ans := 0 for i := 0; i < m; i++ { @@ -184,6 +181,40 @@ func max(a, b int) int { } ``` +### **JavaScript** + +```js +/** + * @param {number[][]} grid + * @return {number} + */ +var getMaximumGold = function (grid) { + const m = grid.length; + const n = grid[0].length; + function dfs(i, j) { + if (i < 0 || i >= m || j < 0 || j >= n || grid[i][j] == 0) { + return 0; + } + const t = grid[i][j]; + grid[i][j] = 0; + let ans = 0; + const dirs = [-1, 0, 1, 0, -1]; + for (let k = 0; k < 4; ++k) { + ans = Math.max(ans, t + dfs(i + dirs[k], j + dirs[k + 1])); + } + grid[i][j] = t; + return ans; + } + let ans = 0; + for (let i = 0; i < m; ++i) { + for (let j = 0; j < n; ++j) { + ans = Math.max(ans, dfs(i, j)); + } + } + return ans; +}; +``` + ### **...** ``` diff --git a/solution/1200-1299/1219.Path with Maximum Gold/Solution.cpp b/solution/1200-1299/1219.Path with Maximum Gold/Solution.cpp index 758358eaf0236..c7bf02522ba4b 100644 --- a/solution/1200-1299/1219.Path with Maximum Gold/Solution.cpp +++ b/solution/1200-1299/1219.Path with Maximum Gold/Solution.cpp @@ -1,24 +1,22 @@ class Solution { public: - vector> grid; vector dirs = {-1, 0, 1, 0, -1}; int getMaximumGold(vector>& grid) { - this->grid = grid; int ans = 0; for (int i = 0; i < grid.size(); ++i) for (int j = 0; j < grid[0].size(); ++j) - ans = max(ans, dfs(i, j)); + ans = max(ans, dfs(i, j, grid)); return ans; } - int dfs(int i, int j) { + int dfs(int i, int j, vector>& grid) { if (i < 0 || i >= grid.size() || j < 0 || j >= grid[0].size() || grid[i][j] == 0) return 0; int t = grid[i][j]; grid[i][j] = 0; - int res = 0; - for (int k = 0; k < 4; ++k) res = max(res, t + dfs(i + dirs[k], j + dirs[k + 1])); + int ans = 0; + for (int k = 0; k < 4; ++k) ans = max(ans, t + dfs(i + dirs[k], j + dirs[k + 1], grid)); grid[i][j] = t; - return res; + return ans; } }; \ No newline at end of file diff --git a/solution/1200-1299/1219.Path with Maximum Gold/Solution.go b/solution/1200-1299/1219.Path with Maximum Gold/Solution.go index f573264846e5b..18260b7ac4bd0 100644 --- a/solution/1200-1299/1219.Path with Maximum Gold/Solution.go +++ b/solution/1200-1299/1219.Path with Maximum Gold/Solution.go @@ -7,13 +7,13 @@ func getMaximumGold(grid [][]int) int { } t := grid[i][j] grid[i][j] = 0 - res := 0 + ans := 0 dirs := []int{-1, 0, 1, 0, -1} for k := 0; k < 4; k++ { - res = max(res, t+dfs(i+dirs[k], j+dirs[k+1])) + ans = max(ans, t+dfs(i+dirs[k], j+dirs[k+1])) } grid[i][j] = t - return res + return ans } ans := 0 for i := 0; i < m; i++ { diff --git a/solution/1200-1299/1219.Path with Maximum Gold/Solution.java b/solution/1200-1299/1219.Path with Maximum Gold/Solution.java index 41156506f0ab0..d828c00693a15 100644 --- a/solution/1200-1299/1219.Path with Maximum Gold/Solution.java +++ b/solution/1200-1299/1219.Path with Maximum Gold/Solution.java @@ -1,11 +1,15 @@ class Solution { private int[][] grid; + private int m; + private int n; public int getMaximumGold(int[][] grid) { + m = grid.length; + n = grid[0].length; this.grid = grid; int ans = 0; - for (int i = 0; i < grid.length; ++i) { - for (int j = 0; j < grid[0].length; ++j) { + for (int i = 0; i < m; ++i) { + for (int j = 0; j < n; ++j) { ans = Math.max(ans, dfs(i, j)); } } @@ -13,17 +17,17 @@ public int getMaximumGold(int[][] grid) { } private int dfs(int i, int j) { - if (i < 0 || i >= grid.length || j < 0 || j >= grid[0].length || grid[i][j] == 0) { + if (i < 0 || i >= m || j < 0 || j >= n || grid[i][j] == 0) { return 0; } int t = grid[i][j]; grid[i][j] = 0; int[] dirs = {-1, 0, 1, 0, -1}; - int res = 0; + int ans = 0; for (int k = 0; k < 4; ++k) { - res = Math.max(res, t + dfs(i + dirs[k], j + dirs[k + 1])); + ans = Math.max(ans, t + dfs(i + dirs[k], j + dirs[k + 1])); } grid[i][j] = t; - return res; + return ans; } } \ No newline at end of file diff --git a/solution/1200-1299/1219.Path with Maximum Gold/Solution.js b/solution/1200-1299/1219.Path with Maximum Gold/Solution.js new file mode 100644 index 0000000000000..2db24f482e1d1 --- /dev/null +++ b/solution/1200-1299/1219.Path with Maximum Gold/Solution.js @@ -0,0 +1,29 @@ +/** + * @param {number[][]} grid + * @return {number} + */ +var getMaximumGold = function (grid) { + const m = grid.length; + const n = grid[0].length; + function dfs(i, j) { + if (i < 0 || i >= m || j < 0 || j >= n || grid[i][j] == 0) { + return 0; + } + const t = grid[i][j]; + grid[i][j] = 0; + let ans = 0; + const dirs = [-1, 0, 1, 0, -1]; + for (let k = 0; k < 4; ++k) { + ans = Math.max(ans, t + dfs(i + dirs[k], j + dirs[k + 1])); + } + grid[i][j] = t; + return ans; + } + let ans = 0; + for (let i = 0; i < m; ++i) { + for (let j = 0; j < n; ++j) { + ans = Math.max(ans, dfs(i, j)); + } + } + return ans; +}; diff --git a/solution/1200-1299/1219.Path with Maximum Gold/Solution.py b/solution/1200-1299/1219.Path with Maximum Gold/Solution.py index 04a9422df3d5b..3224c9c0073f6 100644 --- a/solution/1200-1299/1219.Path with Maximum Gold/Solution.py +++ b/solution/1200-1299/1219.Path with Maximum Gold/Solution.py @@ -1,19 +1,14 @@ class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: def dfs(i, j): - if not (0 <= i < m and 0 <= j < n and grid[i][j]): + if not(0 <= i < m and 0 <= j < n and grid[i][j]): return 0 t = grid[i][j] grid[i][j] = 0 - res = 0 - for a, b in [[0, -1], [0, 1], [1, 0], [-1, 0]]: - res = max(res, t + dfs(i + a, j + b)) + ans = t + max(dfs(i + a, j + b) + for a, b in [[0, 1], [0, -1], [-1, 0], [1, 0]]) grid[i][j] = t - return res + return ans m, n = len(grid), len(grid[0]) - ans = 0 - for i in range(m): - for j in range(n): - ans = max(ans, dfs(i, j)) - return ans + return max(dfs(i, j) for i in range(m) for j in range(n))