diff --git a/README.md b/README.md
index 4314196..c5d0fbd 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
## Best practices for LeetCode solutions
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCode Python](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
Hi there! I'm Lane.
Do you feel that there are too many problems (over 3,450) on the LeetCode and you can't finish them all?
@@ -14,21 +14,25 @@ Here, I will provide you with **common problem-solving patterns** so that you do
**Python, C++, Java, JavaScript, C#, Go, Ruby** languages' solutions are provided for every selected LeetCode problem. Other languages' solutions will be provided in the future. If you have better solutions, welcome to create an issue or PR!
-## How to Use this "Fuck LeetCode" Repo?
+## How to fully demonstrate your abilities to employers and get the offer you want?
+
+[Developer Portfolio](https://github.com/developer-portfolios/developer-portfolio) focuses on bringing value to developers, including resume, portfolio, blog and other functions. With it, your abilities will be better seen by employers!
+
+## How to Use this "Fuck LeetCode" Repository?
I have planned a learning route for you. You just need to do the problems in the order they are listed.
You can skip the more difficult problems and do them later.
## Array
- [344. Reverse String](en/1-1000/344-reverse-string.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
-- [27. Remove Element](en/1-1000/27-remove-element.md) Python, Java, C++, JavaScript, C#, Go, Ruby, **2** ways.
+- [27. Remove Element](en/1-1000/27-remove-element.md) Python, Java, C++, JavaScript, C#, Go, Ruby, **2** approaches.
- [704. Binary Search](en/1-1000/704-binary-search.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
- [977. Squares of a Sorted Array](en/1-1000/977-squares-of-a-sorted-array.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
- [209. Minimum Size Subarray Sum](en/1-1000/209-minimum-size-subarray-sum.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
- [303. Range Sum Query - Immutable](en/1-1000/303-range-sum-query-immutable.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
- [59. Spiral Matrix II](en/1-1000/59-spiral-matrix-ii.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
- [503. Next Greater Element II](en/1-1000/503-next-greater-element-ii.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
-- [3478. Choose K Elements With Maximum Sum](https://leetcoder.net/en/leetcode/3478-choose-k-elements-with-maximum-sum) Python.
+- [3478. Choose K Elements With Maximum Sum](https://leetcodepython.com/en/leetcode/3478-choose-k-elements-with-maximum-sum) Python.
## Linked List
- [203. Remove Linked List Elements](en/1-1000/203-remove-linked-list-elements.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
@@ -45,25 +49,25 @@ You can skip the more difficult problems and do them later.
- [383. Ransom Note](en/1-1000/383-ransom-note.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
- [202. Happy Number](en/1-1000/202-happy-number.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
- [454. 4Sum II](en/1-1000/454-4sum-ii.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
-- [49. Group Anagrams](https://leetcoder.net/en/leetcode/49-group-anagrams) Python, Ruby.
+- [49. Group Anagrams](https://leetcodepython.com/en/leetcode/49-group-anagrams) Python, Ruby.
## String
- [28. Find the Index of the First Occurrence in a String](en/1-1000/28-find-the-index-of-the-first-occurrence-in-a-string.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
- [541. Reverse String II](en/1-1000/541-reverse-string-ii.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
- [459. Repeated Substring Pattern](en/1-1000/459-repeated-substring-pattern.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
-- [833. Find, Replace in String](https://leetcoder.net/en/leetcode/833-find-and-replace-in-string) Python.
+- [833. Find, Replace in String](https://leetcodepython.com/en/leetcode/833-find-and-replace-in-string) Python.
## Two Pointers
-- [15. 3Sum](en/1-1000/15-3sum.md) Python, Java, C++, JavaScript, C#, Go, Ruby, 2 ways.
+- [15. 3Sum](en/1-1000/15-3sum.md) Python, Java, C++, JavaScript, C#, Go, Ruby, 2 approaches.
- [18. 4Sum](en/1-1000/18-4sum.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
## Stack & Queue
- [20. Valid Parentheses](en/1-1000/20-valid-parentheses.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
- [232. Implement Queue using Stacks](en/1-1000/232-implement-queue-using-stacks.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
-- [225. Implement Stack using Queues](en/1-1000/225-implement-stack-using-queues.md) Python, Java, C++, JavaScript, C#, Go, Ruby, 3 ways.
+- [225. Implement Stack using Queues](en/1-1000/225-implement-stack-using-queues.md) Python, Java, C++, JavaScript, C#, Go, Ruby, 3 approaches.
## Binary Tree
-- [144. Binary Tree Preorder Traversal](en/1-1000/144-binary-tree-preorder-traversal.md) Python, 2 ways.
+- [144. Binary Tree Preorder Traversal](en/1-1000/144-binary-tree-preorder-traversal.md) Python, 2 approaches.
## Dynamic Programming
### Easy Problems
@@ -72,12 +76,12 @@ You can skip the more difficult problems and do them later.
### House Robber
- [198. House Robber](en/1-1000/198-house-robber.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
- [213. House Robber II](en/1-1000/213-house-robber-ii.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
-- [337. House Robber III](en/1-1000/337-house-robber-iii.md) Python, Java, C++, JavaScript, C#, Go, Ruby, **2** ways.
+- [337. House Robber III](en/1-1000/337-house-robber-iii.md) Python, Java, C++, JavaScript, C#, Go, Ruby, **2** approaches.
### Knapsack Problems
#### 0/1 Knapsack
-- [416. Partition Equal Subset Sum](en/1-1000/416-partition-equal-subset-sum.md) Python, Java, C++, JavaScript, C#, Go, Ruby, **2** ways.
-- [1049. Last Stone Weight II](en/1001-2000/1049-last-stone-weight-ii.md) Python, Java, C++, JavaScript, C#, Go, Ruby, **2** ways.
+- [416. Partition Equal Subset Sum](en/1-1000/416-partition-equal-subset-sum.md) Python, Java, C++, JavaScript, C#, Go, Ruby, **2** approaches.
+- [1049. Last Stone Weight II](en/1001-2000/1049-last-stone-weight-ii.md) Python, Java, C++, JavaScript, C#, Go, Ruby, **2** approaches.
- [494. Target Sum](en/1-1000/494-target-sum.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
- [474. Ones and Zeroes](en/1-1000/474-ones-and-zeroes.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
@@ -108,7 +112,7 @@ You can skip the more difficult problems and do them later.
- [72. Edit Distance](en/1-1000/72-edit-distance.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
### Hard Problems
-- [3494. Find the Minimum Amount of Time to Brew Potions](https://leetcoder.net/en/leetcode/3494-find-the-minimum-amount-of-time-to-brew-potions) Python, Java, C++, JavaScript, C#, Go, Ruby.
+- [3494. Find the Minimum Amount of Time to Brew Potions](https://leetcodepython.com/en/leetcode/3494-find-the-minimum-amount-of-time-to-brew-potions) Python, Java, C++, JavaScript, C#, Go, Ruby.
## Monotonic Stack
- [739. Daily Temperatures](en/1-1000/739-daily-temperatures.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
@@ -117,26 +121,26 @@ You can skip the more difficult problems and do them later.
- [84. Largest Rectangle in Histogram](en/1-1000/84-largest-rectangle-in-histogram.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
## Graph Theory
-- [797. All Paths From Source to Target](en/1-1000/797-all-paths-from-source-to-target.md) Python, Java, C++, JavaScript, C#, Go, Ruby, **2** ways.
-- [200. Number of Islands](en/1-1000/200-number-of-islands.md) Python, Java, C++, JavaScript, C#, Go, Ruby, **3** ways.
-- [463. Island Perimeter](en/1-1000/463-island-perimeter.md) Python, **2** ways.
-- [695. Max Area of Island](en/1-1000/695-max-area-of-island.md) Python, Java, C++, JavaScript, C#, Go, Ruby, **3** ways.
-- [827. Making A Large Island](en/1-1000/827-making-a-large-island.md) Python, **2** ways.
+- [797. All Paths From Source to Target](en/1-1000/797-all-paths-from-source-to-target.md) Python, Java, C++, JavaScript, C#, Go, Ruby, **2** approaches.
+- [200. Number of Islands](en/1-1000/200-number-of-islands.md) Python, Java, C++, JavaScript, C#, Go, Ruby, **3** approaches.
+- [463. Island Perimeter](en/1-1000/463-island-perimeter.md) Python, **2** approaches.
+- [695. Max Area of Island](en/1-1000/695-max-area-of-island.md) Python, Java, C++, JavaScript, C#, Go, Ruby, **3** approaches.
+- [827. Making A Large Island](en/1-1000/827-making-a-large-island.md) Python, **2** approaches.
- [127. Word Ladder](en/1-1000/127-word-ladder.md) Python.
-- [1971. Find if Path Exists in Graph](en/1001-2000/1971-find-if-path-exists-in-graph.md) Python, Java, C++, JavaScript, C#, Go, Ruby, 2 ways.
+- [1971. Find if Path Exists in Graph](en/1001-2000/1971-find-if-path-exists-in-graph.md) Python, Java, C++, JavaScript, C#, Go, Ruby, 2 approaches.
- [684. Redundant Connection](en/1-1000/684-redundant-connection.md) Python, Java, C++, JavaScript, C#, Go, Ruby.
- [685. Redundant Connection II](en/1-1000/685-redundant-connection-ii.md) Python.
-- [1584. Min Cost to Connect All Points](en/1001-2000/1584-min-cost-to-connect-all-points.md) Python, Java, C++, JavaScript, C#, Go, Ruby, 2 ways.
-- [207. Course Schedule](en/1-1000/207-course-schedule.md) Python, Java, C++, C#, 2 ways.
-- [1514. Path with Maximum Probability](en/1001-2000/1514-path-with-maximum-probability.md) Python, 2 ways.
-- [752. Open the Lock](en/1-1000/752-open-the-lock.md) Python, 2 ways.
-- [743. Network Delay Time](en/1-1000/743-network-delay-time.md) Python, 2 ways.
+- [1584. Min Cost to Connect All Points](en/1001-2000/1584-min-cost-to-connect-all-points.md) Python, Java, C++, JavaScript, C#, Go, Ruby, 2 approaches.
+- [207. Course Schedule](en/1-1000/207-course-schedule.md) Python, Java, C++, C#, 2 approaches.
+- [1514. Path with Maximum Probability](en/1001-2000/1514-path-with-maximum-probability.md) Python, 2 approaches.
+- [752. Open the Lock](en/1-1000/752-open-the-lock.md) Python, 2 approaches.
+- [743. Network Delay Time](en/1-1000/743-network-delay-time.md) Python, 2 approaches.
- [787. Cheapest Flights Within K Stops](en/1-1000/787-cheapest-flights-within-k-stops.md) Python.
- [1334. Find the City With the Smallest Number of Neighbors at a Threshold Distance](en/1001-2000/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.md) Python.
## Other Algorithms
-- [433. Minimum Genetic Mutation](en/1-1000/433-minimum-genetic-mutation.md) Python, 3 ways.
+- [433. Minimum Genetic Mutation](en/1-1000/433-minimum-genetic-mutation.md) Python, 3 approaches.
## "Fuck LeetCode": More Problems
-More LeetCode problems and solutions will be added soon. Updated every day.
+More LeetCode problems and solutions will be added soon. Updated every day.
diff --git a/en/1-1000/1-two-sum.md b/en/1-1000/1-two-sum.md
index b1a9539..3fe7591 100644
--- a/en/1-1000/1-two-sum.md
+++ b/en/1-1000/1-two-sum.md
@@ -1,6 +1,6 @@
-# 1. Two Sum - LeetCode Best Practices
+# 1. Two Sum - LeetCode Python/Java/C++/JS code
-Visit original link: [1. Two Sum - LeetCode Best Practices](https://leetcoder.net/en/leetcode/1-two-sum) for a better experience!
+Visit original link: [1. Two Sum - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/1-two-sum) for a better experience!
LeetCode link: [1. Two Sum](https://leetcode.com/problems/two-sum), difficulty: **Easy**.
@@ -116,7 +116,7 @@ class Solution:
1. In `Map`, `key` is `num`, and `value` is array `index`.
2. Traverse the array, if `target - num` is in `Map`, return it. Otherwise, add `num` to `Map`.
-## Steps
+## Step by Step Solutions
1. In `Map`, `key` is `num`, and `value` is array `index`.
@@ -323,9 +323,9 @@ class Solution:
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [1. Two Sum - LeetCode Best Practices](https://leetcoder.net/en/leetcode/1-two-sum).
+Original link: [1. Two Sum - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/1-two-sum).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/15-3sum.md b/en/1-1000/15-3sum.md
index 48f92ae..049c604 100644
--- a/en/1-1000/15-3sum.md
+++ b/en/1-1000/15-3sum.md
@@ -1,6 +1,6 @@
-# 15. 3Sum - LeetCode Best Practices
+# 15. 3Sum - LeetCode Python/Java/C++/JS code
-Visit original link: [15. 3Sum - LeetCode Best Practices](https://leetcoder.net/en/leetcode/15-3sum) for a better experience!
+Visit original link: [15. 3Sum - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/15-3sum) for a better experience!
LeetCode link: [15. 3Sum](https://leetcode.com/problems/3sum), difficulty: **Medium**.
@@ -82,7 +82,7 @@ Notice that the order of the output and the order of the triplets does not matte
4. If you choose `option 1`, you need to use the `two pointers` algorithm when searching for the other two numbers.
5. For `option 2`, only the `Python` sample code is given. This article focuses on `option 1`.
-## Steps
+## Step by Step Solutions
1. Sort `nums`.
2. Iterate over `nums`.
@@ -507,9 +507,9 @@ def duplicate_removed_nums(nums):
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [15. 3Sum - LeetCode Best Practices](https://leetcoder.net/en/leetcode/15-3sum).
+Original link: [15. 3Sum - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/15-3sum).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/160-intersection-of-two-linked-lists.md b/en/1-1000/160-intersection-of-two-linked-lists.md
index fc3af4d..2b0db7a 100644
--- a/en/1-1000/160-intersection-of-two-linked-lists.md
+++ b/en/1-1000/160-intersection-of-two-linked-lists.md
@@ -1,6 +1,6 @@
-# 160. Intersection of Two Linked Lists - LeetCode Best Practices
+# 160. Intersection of Two Linked Lists - LeetCode Python/Java/C++/JS code
-Visit original link: [160. Intersection of Two Linked Lists - LeetCode Best Practices](https://leetcoder.net/en/leetcode/160-intersection-of-two-linked-lists) for a better experience!
+Visit original link: [160. Intersection of Two Linked Lists - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/160-intersection-of-two-linked-lists) for a better experience!
LeetCode link: [160. Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists), difficulty: **Easy**.
@@ -66,7 +66,7 @@ You must first calculate how many kilometers her home is farther from the school
3. At this time, repeat `node = node.next` on the two linked lists until the same node is found or one of the linked lists has reached the end.
-## Steps
+## Step by Step Solutions
1. First calculate the number of nodes in the two linked lists A and B. The number of nodes in linked list A is `node_count_a`, and the number of nodes in linked list B is `node_count_b`.
@@ -493,9 +493,9 @@ func getIntersectionNode(headA, headB *ListNode) *ListNode {
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [160. Intersection of Two Linked Lists - LeetCode Best Practices](https://leetcoder.net/en/leetcode/160-intersection-of-two-linked-lists).
+Original link: [160. Intersection of Two Linked Lists - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/160-intersection-of-two-linked-lists).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/18-4sum.md b/en/1-1000/18-4sum.md
index 6bc5343..9355759 100644
--- a/en/1-1000/18-4sum.md
+++ b/en/1-1000/18-4sum.md
@@ -1,6 +1,6 @@
-# 18. 4Sum - LeetCode Best Practices
+# 18. 4Sum - LeetCode Python/Java/C++/JS code
-Visit original link: [18. 4Sum - LeetCode Best Practices](https://leetcoder.net/en/leetcode/18-4sum) for a better experience!
+Visit original link: [18. 4Sum - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/18-4sum) for a better experience!
LeetCode link: [18. 4Sum](https://leetcode.com/problems/4sum), difficulty: **Medium**.
@@ -370,9 +370,9 @@ public class Solution {
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [18. 4Sum - LeetCode Best Practices](https://leetcoder.net/en/leetcode/18-4sum).
+Original link: [18. 4Sum - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/18-4sum).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/19-remove-nth-node-from-end-of-list.md b/en/1-1000/19-remove-nth-node-from-end-of-list.md
index 085133c..71206fd 100644
--- a/en/1-1000/19-remove-nth-node-from-end-of-list.md
+++ b/en/1-1000/19-remove-nth-node-from-end-of-list.md
@@ -1,6 +1,6 @@
-# 19. Remove Nth Node From End of List - LeetCode Best Practices
+# 19. Remove Nth Node From End of List - LeetCode Python/Java/C++/JS code
-Visit original link: [19. Remove Nth Node From End of List - LeetCode Best Practices](https://leetcoder.net/en/leetcode/19-remove-nth-node-from-end-of-list) for a better experience!
+Visit original link: [19. Remove Nth Node From End of List - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/19-remove-nth-node-from-end-of-list) for a better experience!
LeetCode link: [19. Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list), difficulty: **Medium**.
@@ -51,7 +51,7 @@ Given the `head` of a linked list, remove the *nth* node from the end
3. When `index == node_count - n`, delete the node by `node.next = node.next.next`.
4. Since the deleted node may be `head`, a virtual node `dummy_node` is used to facilitate unified processing.
-## Steps
+## Step by Step Solutions
1. First find out `node_count`.
@@ -382,9 +382,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [19. Remove Nth Node From End of List - LeetCode Best Practices](https://leetcoder.net/en/leetcode/19-remove-nth-node-from-end-of-list).
+Original link: [19. Remove Nth Node From End of List - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/19-remove-nth-node-from-end-of-list).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/20-valid-parentheses.md b/en/1-1000/20-valid-parentheses.md
index 9e217ef..a4c69ff 100644
--- a/en/1-1000/20-valid-parentheses.md
+++ b/en/1-1000/20-valid-parentheses.md
@@ -1,6 +1,6 @@
-# 20. Valid Parentheses - LeetCode Best Practices
+# 20. Valid Parentheses - LeetCode Python/Java/C++/JS code
-Visit original link: [20. Valid Parentheses - LeetCode Best Practices](https://leetcoder.net/en/leetcode/20-valid-parentheses) for a better experience!
+Visit original link: [20. Valid Parentheses - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/20-valid-parentheses) for a better experience!
LeetCode link: [20. Valid Parentheses](https://leetcode.com/problems/valid-parentheses), difficulty: **Easy**.
@@ -348,9 +348,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [20. Valid Parentheses - LeetCode Best Practices](https://leetcoder.net/en/leetcode/20-valid-parentheses).
+Original link: [20. Valid Parentheses - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/20-valid-parentheses).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/202-happy-number.md b/en/1-1000/202-happy-number.md
index ce8af2d..9c12486 100644
--- a/en/1-1000/202-happy-number.md
+++ b/en/1-1000/202-happy-number.md
@@ -1,6 +1,6 @@
-# 202. Happy Number - LeetCode Best Practices
+# 202. Happy Number - LeetCode Python/Java/C++/JS code
-Visit original link: [202. Happy Number - LeetCode Best Practices](https://leetcoder.net/en/leetcode/202-happy-number) for a better experience!
+Visit original link: [202. Happy Number - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/202-happy-number) for a better experience!
LeetCode link: [202. Happy Number](https://leetcode.com/problems/happy-number), difficulty: **Easy**.
@@ -46,7 +46,7 @@ Return `true` if `n` is *a happy number*, and `false` if not.
2. If `n` has already appeared, it means that the loop has been entered, and `return false`. You can use `Set` to save the `n` that has appeared.
3. Go is the iterative solution, other languages are the recursive solution.
-## Steps
+## Step by Step Solutions
1. Generate a new `n` as the `isHappy(n)` parameter.
@@ -272,9 +272,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [202. Happy Number - LeetCode Best Practices](https://leetcoder.net/en/leetcode/202-happy-number).
+Original link: [202. Happy Number - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/202-happy-number).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/203-remove-linked-list-elements.md b/en/1-1000/203-remove-linked-list-elements.md
index f0fc6bf..91202ef 100644
--- a/en/1-1000/203-remove-linked-list-elements.md
+++ b/en/1-1000/203-remove-linked-list-elements.md
@@ -1,6 +1,6 @@
-# 203. Remove Linked List Elements - LeetCode Best Practices
+# 203. Remove Linked List Elements - LeetCode Python/Java/C++/JS code
-Visit original link: [203. Remove Linked List Elements - LeetCode Best Practices](https://leetcoder.net/en/leetcode/203-remove-linked-list-elements) for a better experience!
+Visit original link: [203. Remove Linked List Elements - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/203-remove-linked-list-elements) for a better experience!
LeetCode link: [203. Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements), difficulty: **Easy**.
@@ -266,9 +266,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [203. Remove Linked List Elements - LeetCode Best Practices](https://leetcoder.net/en/leetcode/203-remove-linked-list-elements).
+Original link: [203. Remove Linked List Elements - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/203-remove-linked-list-elements).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/206-reverse-linked-list.md b/en/1-1000/206-reverse-linked-list.md
index 4d24d57..7960b88 100644
--- a/en/1-1000/206-reverse-linked-list.md
+++ b/en/1-1000/206-reverse-linked-list.md
@@ -1,6 +1,6 @@
-# 206. Reverse Linked List - LeetCode Best Practices
+# 206. Reverse Linked List - LeetCode Python/Java/C++/JS code
-Visit original link: [206. Reverse Linked List - LeetCode Best Practices](https://leetcoder.net/en/leetcode/206-reverse-linked-list) for a better experience!
+Visit original link: [206. Reverse Linked List - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/206-reverse-linked-list) for a better experience!
LeetCode link: [206. Reverse Linked List](https://leetcode.com/problems/reverse-linked-list), difficulty: **Easy**.
@@ -45,7 +45,7 @@ Given the `head` of a singly linked list, reverse the list, and return _the reve
Click to view the answer
It is `while (current != null)`, because the operation to be performed is `current.next = previous`.
-## Steps
+## Step by Step Solutions
1. Traverse all nodes.
@@ -287,9 +287,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [206. Reverse Linked List - LeetCode Best Practices](https://leetcoder.net/en/leetcode/206-reverse-linked-list).
+Original link: [206. Reverse Linked List - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/206-reverse-linked-list).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/209-minimum-size-subarray-sum.md b/en/1-1000/209-minimum-size-subarray-sum.md
index b37341d..7b4416f 100644
--- a/en/1-1000/209-minimum-size-subarray-sum.md
+++ b/en/1-1000/209-minimum-size-subarray-sum.md
@@ -1,6 +1,6 @@
-# 209. Minimum Size Subarray Sum - LeetCode Best Practices
+# 209. Minimum Size Subarray Sum - LeetCode Python/Java/C++/JS code
-Visit original link: [209. Minimum Size Subarray Sum - LeetCode Best Practices](https://leetcoder.net/en/leetcode/209-minimum-size-subarray-sum) for a better experience!
+Visit original link: [209. Minimum Size Subarray Sum - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/209-minimum-size-subarray-sum) for a better experience!
LeetCode link: [209. Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum), difficulty: **Medium**.
@@ -45,7 +45,7 @@ Given an array of positive integers `nums` and a positive integer `target`, retu
For **subarray** problems, you can consider using **Sliding Window Technique**, which is similar to the **Fast & Slow Pointers Approach**.
-## Steps
+## Step by Step Solutions
1. Iterate over the `nums` array, the `index` of the element is named `fastIndex`. Although inconspicuous, this is the most important logic of the *Fast & Slow Pointers Approach*. Please memorize it.
@@ -294,9 +294,9 @@ public:
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [209. Minimum Size Subarray Sum - LeetCode Best Practices](https://leetcoder.net/en/leetcode/209-minimum-size-subarray-sum).
+Original link: [209. Minimum Size Subarray Sum - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/209-minimum-size-subarray-sum).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/225-implement-stack-using-queues.md b/en/1-1000/225-implement-stack-using-queues.md
index a268106..bcf9efb 100644
--- a/en/1-1000/225-implement-stack-using-queues.md
+++ b/en/1-1000/225-implement-stack-using-queues.md
@@ -1,6 +1,6 @@
-# 225. Implement Stack using Queues - LeetCode Best Practices
+# 225. Implement Stack using Queues - LeetCode Python/Java/C++/JS code
-Visit original link: [225. Implement Stack using Queues - LeetCode Best Practices](https://leetcoder.net/en/leetcode/225-implement-stack-using-queues) for a better experience!
+Visit original link: [225. Implement Stack using Queues - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/225-implement-stack-using-queues) for a better experience!
LeetCode link: [225. Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues), difficulty: **Easy**.
@@ -701,9 +701,9 @@ public class MyStack
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [225. Implement Stack using Queues - LeetCode Best Practices](https://leetcoder.net/en/leetcode/225-implement-stack-using-queues).
+Original link: [225. Implement Stack using Queues - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/225-implement-stack-using-queues).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/232-implement-queue-using-stacks.md b/en/1-1000/232-implement-queue-using-stacks.md
index 2873d09..763dce3 100644
--- a/en/1-1000/232-implement-queue-using-stacks.md
+++ b/en/1-1000/232-implement-queue-using-stacks.md
@@ -1,6 +1,6 @@
-# 232. Implement Queue using Stacks - LeetCode Best Practices
+# 232. Implement Queue using Stacks - LeetCode Python/Java/C++/JS code
-Visit original link: [232. Implement Queue using Stacks - LeetCode Best Practices](https://leetcoder.net/en/leetcode/232-implement-queue-using-stacks) for a better experience!
+Visit original link: [232. Implement Queue using Stacks - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/232-implement-queue-using-stacks) for a better experience!
LeetCode link: [232. Implement Queue using Stacks](https://leetcode.com/problems/implement-queue-using-stacks), difficulty: **Easy**.
@@ -348,9 +348,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [232. Implement Queue using Stacks - LeetCode Best Practices](https://leetcoder.net/en/leetcode/232-implement-queue-using-stacks).
+Original link: [232. Implement Queue using Stacks - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/232-implement-queue-using-stacks).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/24-swap-nodes-in-pairs.md b/en/1-1000/24-swap-nodes-in-pairs.md
index 6eb16c0..b55ba36 100644
--- a/en/1-1000/24-swap-nodes-in-pairs.md
+++ b/en/1-1000/24-swap-nodes-in-pairs.md
@@ -1,6 +1,6 @@
-# 24. Swap Nodes in Pairs - LeetCode Best Practices
+# 24. Swap Nodes in Pairs - LeetCode Python/Java/C++/JS code
-Visit original link: [24. Swap Nodes in Pairs - LeetCode Best Practices](https://leetcoder.net/en/leetcode/24-swap-nodes-in-pairs) for a better experience!
+Visit original link: [24. Swap Nodes in Pairs - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/24-swap-nodes-in-pairs) for a better experience!
LeetCode link: [24. Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs), difficulty: **Medium**.
@@ -46,7 +46,7 @@ Before solving this problem, it is recommended to solve the simple problem [206.
1. To solve this problem, you still need to define at least two variables: `current` and `previous`.
2. The loop condition should be `while (current.next != null)` instead of `while (current != null)`, because the operations that need to be performed include `current.next.next`.
-## Steps
+## Step by Step Solutions
1. Traverse all nodes.
@@ -370,9 +370,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [24. Swap Nodes in Pairs - LeetCode Best Practices](https://leetcoder.net/en/leetcode/24-swap-nodes-in-pairs).
+Original link: [24. Swap Nodes in Pairs - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/24-swap-nodes-in-pairs).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/242-valid-anagram.md b/en/1-1000/242-valid-anagram.md
index 30a6f25..bc9d062 100644
--- a/en/1-1000/242-valid-anagram.md
+++ b/en/1-1000/242-valid-anagram.md
@@ -1,6 +1,6 @@
-# 242. Valid Anagram - LeetCode Best Practices
+# 242. Valid Anagram - LeetCode Python/Java/C++/JS code
-Visit original link: [242. Valid Anagram - LeetCode Best Practices](https://leetcoder.net/en/leetcode/242-valid-anagram) for a better experience!
+Visit original link: [242. Valid Anagram - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/242-valid-anagram) for a better experience!
LeetCode link: [242. Valid Anagram](https://leetcode.com/problems/valid-anagram), difficulty: **Easy**.
@@ -215,9 +215,9 @@ public:
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [242. Valid Anagram - LeetCode Best Practices](https://leetcoder.net/en/leetcode/242-valid-anagram).
+Original link: [242. Valid Anagram - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/242-valid-anagram).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/27-remove-element.md b/en/1-1000/27-remove-element.md
index bb96cba..26f48e6 100644
--- a/en/1-1000/27-remove-element.md
+++ b/en/1-1000/27-remove-element.md
@@ -1,6 +1,6 @@
-# 27. Remove Element - LeetCode Best Practices
+# 27. Remove Element - LeetCode Python/Java/C++/JS code
-Visit original link: [27. Remove Element - LeetCode Best Practices](https://leetcoder.net/en/leetcode/27-remove-element) for a better experience!
+Visit original link: [27. Remove Element - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/27-remove-element) for a better experience!
LeetCode link: [27. Remove Element](https://leetcode.com/problems/remove-element), difficulty: **Easy**.
@@ -428,9 +428,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [27. Remove Element - LeetCode Best Practices](https://leetcoder.net/en/leetcode/27-remove-element).
+Original link: [27. Remove Element - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/27-remove-element).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/28-find-the-index-of-the-first-occurrence-in-a-string.md b/en/1-1000/28-find-the-index-of-the-first-occurrence-in-a-string.md
index e44ec5b..b42d4b8 100644
--- a/en/1-1000/28-find-the-index-of-the-first-occurrence-in-a-string.md
+++ b/en/1-1000/28-find-the-index-of-the-first-occurrence-in-a-string.md
@@ -1,6 +1,6 @@
-# 28. Find the Index of the First Occurrence in a String - LeetCode Best Practices
+# 28. Find the Index of the First Occurrence in a String - LeetCode Python/Java/C++/JS code
-Visit original link: [28. Find the Index of the First Occurrence in a String - LeetCode Best Practices](https://leetcoder.net/en/leetcode/28-find-the-index-of-the-first-occurrence-in-a-string) for a better experience!
+Visit original link: [28. Find the Index of the First Occurrence in a String - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/28-find-the-index-of-the-first-occurrence-in-a-string) for a better experience!
LeetCode link: [28. Find the Index of the First Occurrence in a String](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string), difficulty: **Easy**.
@@ -202,9 +202,9 @@ public class Solution {
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [28. Find the Index of the First Occurrence in a String - LeetCode Best Practices](https://leetcoder.net/en/leetcode/28-find-the-index-of-the-first-occurrence-in-a-string).
+Original link: [28. Find the Index of the First Occurrence in a String - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/28-find-the-index-of-the-first-occurrence-in-a-string).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/303-range-sum-query-immutable.md b/en/1-1000/303-range-sum-query-immutable.md
index 18bad57..d74af02 100644
--- a/en/1-1000/303-range-sum-query-immutable.md
+++ b/en/1-1000/303-range-sum-query-immutable.md
@@ -1,6 +1,6 @@
-# 303. Range Sum Query - Immutable - LeetCode Best Practices
+# 303. Range Sum Query - Immutable - LeetCode Python/Java/C++/JS code
-Visit original link: [303. Range Sum Query - Immutable - LeetCode Best Practices](https://leetcoder.net/en/leetcode/303-range-sum-query-immutable) for a better experience!
+Visit original link: [303. Range Sum Query - Immutable - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/303-range-sum-query-immutable) for a better experience!
LeetCode link: [303. Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable), difficulty: **Easy**.
@@ -232,9 +232,9 @@ class NumArray:
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [303. Range Sum Query - Immutable - LeetCode Best Practices](https://leetcoder.net/en/leetcode/303-range-sum-query-immutable).
+Original link: [303. Range Sum Query - Immutable - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/303-range-sum-query-immutable).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/344-reverse-string.md b/en/1-1000/344-reverse-string.md
index 41320ba..ec4401c 100644
--- a/en/1-1000/344-reverse-string.md
+++ b/en/1-1000/344-reverse-string.md
@@ -1,6 +1,6 @@
-# 344. Reverse String - LeetCode Best Practices
+# 344. Reverse String - LeetCode Python/Java/C++/JS code
-Visit original link: [344. Reverse String - LeetCode Best Practices](https://leetcoder.net/en/leetcode/344-reverse-string) for a better experience!
+Visit original link: [344. Reverse String - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/344-reverse-string) for a better experience!
LeetCode link: [344. Reverse String](https://leetcode.com/problems/reverse-string), difficulty: **Easy**.
@@ -44,7 +44,7 @@ You must do this by modifying the input array [in-place](https://en.wikipedia.or
4. In the loop body, swap the two values.
5. The above is the template for `two pointers` in `opposite directions`.
-## Steps
+## Step by Step Solutions
1. Use two pointers with **opposite directions**, initially one pointer points to the index `0` and the other pointer points to the index `s.length - 1`.
@@ -212,9 +212,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [344. Reverse String - LeetCode Best Practices](https://leetcoder.net/en/leetcode/344-reverse-string).
+Original link: [344. Reverse String - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/344-reverse-string).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/349-intersection-of-two-arrays.md b/en/1-1000/349-intersection-of-two-arrays.md
index b3cd8d6..1ba630d 100644
--- a/en/1-1000/349-intersection-of-two-arrays.md
+++ b/en/1-1000/349-intersection-of-two-arrays.md
@@ -1,6 +1,6 @@
-# 349. Intersection of Two Arrays - LeetCode Best Practices
+# 349. Intersection of Two Arrays - LeetCode Python/Java/C++/JS code
-Visit original link: [349. Intersection of Two Arrays - LeetCode Best Practices](https://leetcoder.net/en/leetcode/349-intersection-of-two-arrays) for a better experience!
+Visit original link: [349. Intersection of Two Arrays - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/349-intersection-of-two-arrays) for a better experience!
LeetCode link: [349. Intersection of Two Arrays](https://leetcode.com/problems/intersection-of-two-arrays), difficulty: **Easy**.
@@ -187,9 +187,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [349. Intersection of Two Arrays - LeetCode Best Practices](https://leetcoder.net/en/leetcode/349-intersection-of-two-arrays).
+Original link: [349. Intersection of Two Arrays - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/349-intersection-of-two-arrays).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/383-ransom-note.md b/en/1-1000/383-ransom-note.md
index 85586df..77c269a 100644
--- a/en/1-1000/383-ransom-note.md
+++ b/en/1-1000/383-ransom-note.md
@@ -1,6 +1,6 @@
-# 383. Ransom Note - LeetCode Best Practices
+# 383. Ransom Note - LeetCode Python/Java/C++/JS code
-Visit original link: [383. Ransom Note - LeetCode Best Practices](https://leetcoder.net/en/leetcode/383-ransom-note) for a better experience!
+Visit original link: [383. Ransom Note - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/383-ransom-note) for a better experience!
LeetCode link: [383. Ransom Note](https://leetcode.com/problems/ransom-note), difficulty: **Easy**.
@@ -43,7 +43,7 @@ Each letter in `magazine` can only be used once in `ransomNote`.
Click to view the answer
Traverses `ransomNote` and subtracts one from the number corresponding to the current character (reverse operation). If the number of a character is less than 0, return `false`.
-## Steps
+## Step by Step Solutions
1. First count the characters in `magazine`, and store the results in `Map`.
@@ -244,9 +244,9 @@ public:
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [383. Ransom Note - LeetCode Best Practices](https://leetcoder.net/en/leetcode/383-ransom-note).
+Original link: [383. Ransom Note - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/383-ransom-note).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/392-is-subsequence.md b/en/1-1000/392-is-subsequence.md
index 9064b13..737baa4 100644
--- a/en/1-1000/392-is-subsequence.md
+++ b/en/1-1000/392-is-subsequence.md
@@ -1,6 +1,6 @@
-# 392. Is Subsequence - LeetCode Best Practices
+# 392. Is Subsequence - LeetCode Python/Java/C++/JS code
-Visit original link: [392. Is Subsequence - LeetCode Best Practices](https://leetcoder.net/en/leetcode/392-is-subsequence) for a better experience!
+Visit original link: [392. Is Subsequence - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/392-is-subsequence) for a better experience!
LeetCode link: [392. Is Subsequence](https://leetcode.com/problems/is-subsequence), difficulty: **Medium**.
@@ -243,15 +243,15 @@ end
#### "Dynamic programming" is divided into five steps
-1. Determine the meaning of each value of the array `dp`.
+1. Determine the **meaning** of each value of the array `dp`.
2. Initialize the value of the array `dp`.
-3. Fill in the `dp` grid data "in order" according to an example.
-4. Based on the `dp` grid data, derive the "recursive formula".
+3. Fill in the `dp` grid data **in order** according to an example.
+4. Based on the `dp` grid data, derive the **recursive formula**.
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
#### Detailed description of these five steps
-1. Determine the meaning of each value of the array `dp`.
+1. Determine the **meaning** of each value of the array `dp`.
- First determine whether `dp` is a one-dimensional array or a two-dimensional array. A `one-dimensional rolling array` means that the values of the array are overwritten at each iteration. Most of the time, using `one-dimensional rolling array` instead of `two-dimensional array` can simplify the code; but for some problems, such as operating "two swappable arrays", for the sake of ease of understanding, it is better to use `two-dimensional array`.
- Try to use the meaning of the `return value` required by the problem as the meaning of `dp[i]` (one-dimensional) or `dp[i][j]` (two-dimensional). It works about 60% of the time. If it doesn't work, try other meanings.
- Try to save more information in the design. Repeated information only needs to be saved once in a `dp[i]`.
@@ -259,14 +259,14 @@ end
2. Initialize the value of the array `dp`. The value of `dp` involves two levels:
1. The length of `dp`. Usually: `condition array length plus 1` or `condition array length`.
2. The value of `dp[i]` or `dp[i][j]`. `dp[0]` or `dp[0][0]` sometimes requires special treatment.
-3. Fill in the `dp` grid data "in order" according to an example.
+3. Fill in the `dp` grid data **in order** according to an example.
- The "recursive formula" is the core of the "dynamic programming" algorithm. But the "recursive formula" is obscure. If you want to get it, you need to make a table and use data to inspire yourself.
- If the original example is not good enough, you need to redesign one yourself.
- According to the example, fill in the `dp` grid data "in order", which is very important because it determines the traversal order of the code.
- Most of the time, from left to right, from top to bottom. But sometimes it is necessary to traverse from right to left, from bottom to top, from the middle to the right (or left), such as the "palindrome" problems. Sometimes, it is necessary to traverse a line twice, first forward and then backward.
- When the order is determined correctly, the starting point is determined. Starting from the starting point, fill in the `dp` grid data "in order". This order is also the order in which the program processes.
- In this process, you will get inspiration to write a "recursive formula". If you can already derive the formula, you do not need to complete the grid.
-4. Based on the `dp` grid data, derive the "recursive formula".
+4. Based on the `dp` grid data, derive the **recursive formula**.
- There are three special positions to pay attention to: `dp[i - 1][j - 1]`, `dp[i - 1][j]` and `dp[i][j - 1]`, the current `dp[i][j]` often depends on them.
- When operating "two swappable arrays", due to symmetry, we may need to use `dp[i - 1][j]` and `dp[i][j - 1]` at the same time.
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
@@ -274,7 +274,7 @@ end
After reading the above, do you feel that "dynamic programming" is not that difficult? Try to solve this problem. 🤗
-## Steps
+## Step by Step Solutions
1. Determine the **meaning** of the `dp[i][j]`.
- `dp[i][j]` represents whether the first `i` letters of `s` are a subsequence of `t`'s first `j` letters.
@@ -507,9 +507,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [392. Is Subsequence - LeetCode Best Practices](https://leetcoder.net/en/leetcode/392-is-subsequence).
+Original link: [392. Is Subsequence - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/392-is-subsequence).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/416-partition-equal-subset-sum.md b/en/1-1000/416-partition-equal-subset-sum.md
index 120147d..22de589 100644
--- a/en/1-1000/416-partition-equal-subset-sum.md
+++ b/en/1-1000/416-partition-equal-subset-sum.md
@@ -1,6 +1,6 @@
-# 416. Partition Equal Subset Sum - LeetCode Best Practices
+# 416. Partition Equal Subset Sum - LeetCode Python/Java/C++/JS code
-Visit original link: [416. Partition Equal Subset Sum - LeetCode Best Practices](https://leetcoder.net/en/leetcode/416-partition-equal-subset-sum) for a better experience!
+Visit original link: [416. Partition Equal Subset Sum - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/416-partition-equal-subset-sum) for a better experience!
LeetCode link: [416. Partition Equal Subset Sum](https://leetcode.com/problems/partition-equal-subset-sum), difficulty: **Medium**.
@@ -46,15 +46,15 @@ Given an integer array `nums`, return `true` if you can partition the array into
#### "Dynamic programming" is divided into five steps
-1. Determine the meaning of each value of the array `dp`.
+1. Determine the **meaning** of each value of the array `dp`.
2. Initialize the value of the array `dp`.
-3. Fill in the `dp` grid data "in order" according to an example.
-4. Based on the `dp` grid data, derive the "recursive formula".
+3. Fill in the `dp` grid data **in order** according to an example.
+4. Based on the `dp` grid data, derive the **recursive formula**.
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
#### Detailed description of these five steps
-1. Determine the meaning of each value of the array `dp`.
+1. Determine the **meaning** of each value of the array `dp`.
- First determine whether `dp` is a one-dimensional array or a two-dimensional array. A `one-dimensional rolling array` means that the values of the array are overwritten at each iteration. Most of the time, using `one-dimensional rolling array` instead of `two-dimensional array` can simplify the code; but for some problems, such as operating "two swappable arrays", for the sake of ease of understanding, it is better to use `two-dimensional array`.
- Try to use the meaning of the `return value` required by the problem as the meaning of `dp[i]` (one-dimensional) or `dp[i][j]` (two-dimensional). It works about 60% of the time. If it doesn't work, try other meanings.
- Try to save more information in the design. Repeated information only needs to be saved once in a `dp[i]`.
@@ -62,14 +62,14 @@ Given an integer array `nums`, return `true` if you can partition the array into
2. Initialize the value of the array `dp`. The value of `dp` involves two levels:
1. The length of `dp`. Usually: `condition array length plus 1` or `condition array length`.
2. The value of `dp[i]` or `dp[i][j]`. `dp[0]` or `dp[0][0]` sometimes requires special treatment.
-3. Fill in the `dp` grid data "in order" according to an example.
+3. Fill in the `dp` grid data **in order** according to an example.
- The "recursive formula" is the core of the "dynamic programming" algorithm. But the "recursive formula" is obscure. If you want to get it, you need to make a table and use data to inspire yourself.
- If the original example is not good enough, you need to redesign one yourself.
- According to the example, fill in the `dp` grid data "in order", which is very important because it determines the traversal order of the code.
- Most of the time, from left to right, from top to bottom. But sometimes it is necessary to traverse from right to left, from bottom to top, from the middle to the right (or left), such as the "palindrome" problems. Sometimes, it is necessary to traverse a line twice, first forward and then backward.
- When the order is determined correctly, the starting point is determined. Starting from the starting point, fill in the `dp` grid data "in order". This order is also the order in which the program processes.
- In this process, you will get inspiration to write a "recursive formula". If you can already derive the formula, you do not need to complete the grid.
-4. Based on the `dp` grid data, derive the "recursive formula".
+4. Based on the `dp` grid data, derive the **recursive formula**.
- There are three special positions to pay attention to: `dp[i - 1][j - 1]`, `dp[i - 1][j]` and `dp[i][j - 1]`, the current `dp[i][j]` often depends on them.
- When operating "two swappable arrays", due to symmetry, we may need to use `dp[i - 1][j]` and `dp[i][j - 1]` at the same time.
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
@@ -112,7 +112,7 @@ Because "0/1 Knapsack Problem" belongs to "Dynamic Programming", I will explain
```
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
-## Steps
+## Step by Step Solutions
1. Determine the **meaning** of the `dp[j]`
- `dp[j]` represents whether it is possible to `sum` the first `i` `nums` to get `j`.
@@ -375,15 +375,15 @@ During the interview, you need to remember it. Is there any way to not worry abo
#### "Dynamic programming" is divided into five steps
-1. Determine the meaning of each value of the array `dp`.
+1. Determine the **meaning** of each value of the array `dp`.
2. Initialize the value of the array `dp`.
-3. Fill in the `dp` grid data "in order" according to an example.
-4. Based on the `dp` grid data, derive the "recursive formula".
+3. Fill in the `dp` grid data **in order** according to an example.
+4. Based on the `dp` grid data, derive the **recursive formula**.
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
#### Detailed description of these five steps
-1. Determine the meaning of each value of the array `dp`.
+1. Determine the **meaning** of each value of the array `dp`.
- First determine whether `dp` is a one-dimensional array or a two-dimensional array. A `one-dimensional rolling array` means that the values of the array are overwritten at each iteration. Most of the time, using `one-dimensional rolling array` instead of `two-dimensional array` can simplify the code; but for some problems, such as operating "two swappable arrays", for the sake of ease of understanding, it is better to use `two-dimensional array`.
- Try to use the meaning of the `return value` required by the problem as the meaning of `dp[i]` (one-dimensional) or `dp[i][j]` (two-dimensional). It works about 60% of the time. If it doesn't work, try other meanings.
- Try to save more information in the design. Repeated information only needs to be saved once in a `dp[i]`.
@@ -391,14 +391,14 @@ During the interview, you need to remember it. Is there any way to not worry abo
2. Initialize the value of the array `dp`. The value of `dp` involves two levels:
1. The length of `dp`. Usually: `condition array length plus 1` or `condition array length`.
2. The value of `dp[i]` or `dp[i][j]`. `dp[0]` or `dp[0][0]` sometimes requires special treatment.
-3. Fill in the `dp` grid data "in order" according to an example.
+3. Fill in the `dp` grid data **in order** according to an example.
- The "recursive formula" is the core of the "dynamic programming" algorithm. But the "recursive formula" is obscure. If you want to get it, you need to make a table and use data to inspire yourself.
- If the original example is not good enough, you need to redesign one yourself.
- According to the example, fill in the `dp` grid data "in order", which is very important because it determines the traversal order of the code.
- Most of the time, from left to right, from top to bottom. But sometimes it is necessary to traverse from right to left, from bottom to top, from the middle to the right (or left), such as the "palindrome" problems. Sometimes, it is necessary to traverse a line twice, first forward and then backward.
- When the order is determined correctly, the starting point is determined. Starting from the starting point, fill in the `dp` grid data "in order". This order is also the order in which the program processes.
- In this process, you will get inspiration to write a "recursive formula". If you can already derive the formula, you do not need to complete the grid.
-4. Based on the `dp` grid data, derive the "recursive formula".
+4. Based on the `dp` grid data, derive the **recursive formula**.
- There are three special positions to pay attention to: `dp[i - 1][j - 1]`, `dp[i - 1][j]` and `dp[i][j - 1]`, the current `dp[i][j]` often depends on them.
- When operating "two swappable arrays", due to symmetry, we may need to use `dp[i - 1][j]` and `dp[i][j - 1]` at the same time.
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
@@ -601,9 +601,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [416. Partition Equal Subset Sum - LeetCode Best Practices](https://leetcoder.net/en/leetcode/416-partition-equal-subset-sum).
+Original link: [416. Partition Equal Subset Sum - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/416-partition-equal-subset-sum).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/454-4sum-ii.md b/en/1-1000/454-4sum-ii.md
index a8c0933..3dcd371 100644
--- a/en/1-1000/454-4sum-ii.md
+++ b/en/1-1000/454-4sum-ii.md
@@ -1,6 +1,6 @@
-# 454. 4Sum II - LeetCode Best Practices
+# 454. 4Sum II - LeetCode Python/Java/C++/JS code
-Visit original link: [454. 4Sum II - LeetCode Best Practices](https://leetcoder.net/en/leetcode/454-4sum-ii) for a better experience!
+Visit original link: [454. 4Sum II - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/454-4sum-ii) for a better experience!
LeetCode link: [454. 4Sum II](https://leetcode.com/problems/4sum-ii), difficulty: **Medium**.
@@ -48,7 +48,7 @@ Given four integer arrays `nums1`, `nums2`, `nums3`, and `nums4` all of length `
2. Count the number of each `sum`. Use `Map` to store, `key` is `sum`, `value` is `count`.
3. Iterate over `nums3` and `nums4`, if `-(num3 + num4)` exists in `keys` of `Map`, then `count` is included in the total.
-## Steps
+## Step by Step Solutions
1. Count the number of each `sum`. Use `Map` to store, `key` is `sum`, `value` is `count`.
@@ -271,9 +271,9 @@ public:
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [454. 4Sum II - LeetCode Best Practices](https://leetcoder.net/en/leetcode/454-4sum-ii).
+Original link: [454. 4Sum II - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/454-4sum-ii).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/459-repeated-substring-pattern.md b/en/1-1000/459-repeated-substring-pattern.md
index 7441d6d..c95b84b 100644
--- a/en/1-1000/459-repeated-substring-pattern.md
+++ b/en/1-1000/459-repeated-substring-pattern.md
@@ -1,6 +1,6 @@
-# 459. Repeated Substring Pattern - LeetCode Best Practices
+# 459. Repeated Substring Pattern - LeetCode Python/Java/C++/JS code
-Visit original link: [459. Repeated Substring Pattern - LeetCode Best Practices](https://leetcoder.net/en/leetcode/459-repeated-substring-pattern) for a better experience!
+Visit original link: [459. Repeated Substring Pattern - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/459-repeated-substring-pattern) for a better experience!
LeetCode link: [459. Repeated Substring Pattern](https://leetcode.com/problems/repeated-substring-pattern), difficulty: **Easy**.
@@ -224,9 +224,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [459. Repeated Substring Pattern - LeetCode Best Practices](https://leetcoder.net/en/leetcode/459-repeated-substring-pattern).
+Original link: [459. Repeated Substring Pattern - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/459-repeated-substring-pattern).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/474-ones-and-zeroes.md b/en/1-1000/474-ones-and-zeroes.md
index a9003c0..ad43c7f 100644
--- a/en/1-1000/474-ones-and-zeroes.md
+++ b/en/1-1000/474-ones-and-zeroes.md
@@ -1,6 +1,6 @@
-# 474. Ones and Zeroes - LeetCode Best Practices
+# 474. Ones and Zeroes - LeetCode Python/Java/C++/JS code
-Visit original link: [474. Ones and Zeroes - LeetCode Best Practices](https://leetcoder.net/en/leetcode/474-ones-and-zeroes) for a better experience!
+Visit original link: [474. Ones and Zeroes - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/474-ones-and-zeroes) for a better experience!
LeetCode link: [474. Ones and Zeroes](https://leetcode.com/problems/ones-and-zeroes), difficulty: **Medium**.
@@ -57,15 +57,15 @@ This question is difficult. It is recommended to complete a simple question of t
#### "Dynamic programming" is divided into five steps
-1. Determine the meaning of each value of the array `dp`.
+1. Determine the **meaning** of each value of the array `dp`.
2. Initialize the value of the array `dp`.
-3. Fill in the `dp` grid data "in order" according to an example.
-4. Based on the `dp` grid data, derive the "recursive formula".
+3. Fill in the `dp` grid data **in order** according to an example.
+4. Based on the `dp` grid data, derive the **recursive formula**.
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
#### Detailed description of these five steps
-1. Determine the meaning of each value of the array `dp`.
+1. Determine the **meaning** of each value of the array `dp`.
- First determine whether `dp` is a one-dimensional array or a two-dimensional array. A `one-dimensional rolling array` means that the values of the array are overwritten at each iteration. Most of the time, using `one-dimensional rolling array` instead of `two-dimensional array` can simplify the code; but for some problems, such as operating "two swappable arrays", for the sake of ease of understanding, it is better to use `two-dimensional array`.
- Try to use the meaning of the `return value` required by the problem as the meaning of `dp[i]` (one-dimensional) or `dp[i][j]` (two-dimensional). It works about 60% of the time. If it doesn't work, try other meanings.
- Try to save more information in the design. Repeated information only needs to be saved once in a `dp[i]`.
@@ -73,14 +73,14 @@ This question is difficult. It is recommended to complete a simple question of t
2. Initialize the value of the array `dp`. The value of `dp` involves two levels:
1. The length of `dp`. Usually: `condition array length plus 1` or `condition array length`.
2. The value of `dp[i]` or `dp[i][j]`. `dp[0]` or `dp[0][0]` sometimes requires special treatment.
-3. Fill in the `dp` grid data "in order" according to an example.
+3. Fill in the `dp` grid data **in order** according to an example.
- The "recursive formula" is the core of the "dynamic programming" algorithm. But the "recursive formula" is obscure. If you want to get it, you need to make a table and use data to inspire yourself.
- If the original example is not good enough, you need to redesign one yourself.
- According to the example, fill in the `dp` grid data "in order", which is very important because it determines the traversal order of the code.
- Most of the time, from left to right, from top to bottom. But sometimes it is necessary to traverse from right to left, from bottom to top, from the middle to the right (or left), such as the "palindrome" problems. Sometimes, it is necessary to traverse a line twice, first forward and then backward.
- When the order is determined correctly, the starting point is determined. Starting from the starting point, fill in the `dp` grid data "in order". This order is also the order in which the program processes.
- In this process, you will get inspiration to write a "recursive formula". If you can already derive the formula, you do not need to complete the grid.
-4. Based on the `dp` grid data, derive the "recursive formula".
+4. Based on the `dp` grid data, derive the **recursive formula**.
- There are three special positions to pay attention to: `dp[i - 1][j - 1]`, `dp[i - 1][j]` and `dp[i][j - 1]`, the current `dp[i][j]` often depends on them.
- When operating "two swappable arrays", due to symmetry, we may need to use `dp[i - 1][j]` and `dp[i][j - 1]` at the same time.
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
@@ -123,7 +123,7 @@ Because "0/1 Knapsack Problem" belongs to "Dynamic Programming", I will explain
```
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
-## Steps
+## Step by Step Solutions
1. Determine the **meaning** of the `dp[j]`
- Since we are only considering the zero count constraint for now, we can use a one-dimensional `dp` array.
@@ -468,9 +468,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [474. Ones and Zeroes - LeetCode Best Practices](https://leetcoder.net/en/leetcode/474-ones-and-zeroes).
+Original link: [474. Ones and Zeroes - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/474-ones-and-zeroes).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/49-group-anagrams.md b/en/1-1000/49-group-anagrams.md
index 00177b5..2967e36 100644
--- a/en/1-1000/49-group-anagrams.md
+++ b/en/1-1000/49-group-anagrams.md
@@ -1,6 +1,6 @@
-# 49. Group Anagrams - LeetCode Best Practices
+# 49. Group Anagrams - LeetCode Python/Java/C++/JS code
-Visit original link: [49. Group Anagrams - LeetCode Best Practices](https://leetcoder.net/en/leetcode/49-group-anagrams) for a better experience!
+Visit original link: [49. Group Anagrams - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/49-group-anagrams) for a better experience!
LeetCode link: [49. Group Anagrams](https://leetcode.com/problems/group-anagrams), difficulty: **Medium**.
@@ -102,9 +102,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [49. Group Anagrams - LeetCode Best Practices](https://leetcoder.net/en/leetcode/49-group-anagrams).
+Original link: [49. Group Anagrams - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/49-group-anagrams).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/494-target-sum.md b/en/1-1000/494-target-sum.md
index 356a436..3a9d5c5 100644
--- a/en/1-1000/494-target-sum.md
+++ b/en/1-1000/494-target-sum.md
@@ -1,6 +1,6 @@
-# 494. Target Sum - LeetCode Best Practices
+# 494. Target Sum - LeetCode Python/Java/C++/JS code
-Visit original link: [494. Target Sum - LeetCode Best Practices](https://leetcoder.net/en/leetcode/494-target-sum) for a better experience!
+Visit original link: [494. Target Sum - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/494-target-sum) for a better experience!
LeetCode link: [494. Target Sum](https://leetcode.com/problems/target-sum), difficulty: **Medium**.
@@ -52,15 +52,15 @@ This problem is quite difficult if you have not solved similar problems before.
#### "Dynamic programming" is divided into five steps
-1. Determine the meaning of each value of the array `dp`.
+1. Determine the **meaning** of each value of the array `dp`.
2. Initialize the value of the array `dp`.
-3. Fill in the `dp` grid data "in order" according to an example.
-4. Based on the `dp` grid data, derive the "recursive formula".
+3. Fill in the `dp` grid data **in order** according to an example.
+4. Based on the `dp` grid data, derive the **recursive formula**.
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
#### Detailed description of these five steps
-1. Determine the meaning of each value of the array `dp`.
+1. Determine the **meaning** of each value of the array `dp`.
- First determine whether `dp` is a one-dimensional array or a two-dimensional array. A `one-dimensional rolling array` means that the values of the array are overwritten at each iteration. Most of the time, using `one-dimensional rolling array` instead of `two-dimensional array` can simplify the code; but for some problems, such as operating "two swappable arrays", for the sake of ease of understanding, it is better to use `two-dimensional array`.
- Try to use the meaning of the `return value` required by the problem as the meaning of `dp[i]` (one-dimensional) or `dp[i][j]` (two-dimensional). It works about 60% of the time. If it doesn't work, try other meanings.
- Try to save more information in the design. Repeated information only needs to be saved once in a `dp[i]`.
@@ -68,14 +68,14 @@ This problem is quite difficult if you have not solved similar problems before.
2. Initialize the value of the array `dp`. The value of `dp` involves two levels:
1. The length of `dp`. Usually: `condition array length plus 1` or `condition array length`.
2. The value of `dp[i]` or `dp[i][j]`. `dp[0]` or `dp[0][0]` sometimes requires special treatment.
-3. Fill in the `dp` grid data "in order" according to an example.
+3. Fill in the `dp` grid data **in order** according to an example.
- The "recursive formula" is the core of the "dynamic programming" algorithm. But the "recursive formula" is obscure. If you want to get it, you need to make a table and use data to inspire yourself.
- If the original example is not good enough, you need to redesign one yourself.
- According to the example, fill in the `dp` grid data "in order", which is very important because it determines the traversal order of the code.
- Most of the time, from left to right, from top to bottom. But sometimes it is necessary to traverse from right to left, from bottom to top, from the middle to the right (or left), such as the "palindrome" problems. Sometimes, it is necessary to traverse a line twice, first forward and then backward.
- When the order is determined correctly, the starting point is determined. Starting from the starting point, fill in the `dp` grid data "in order". This order is also the order in which the program processes.
- In this process, you will get inspiration to write a "recursive formula". If you can already derive the formula, you do not need to complete the grid.
-4. Based on the `dp` grid data, derive the "recursive formula".
+4. Based on the `dp` grid data, derive the **recursive formula**.
- There are three special positions to pay attention to: `dp[i - 1][j - 1]`, `dp[i - 1][j]` and `dp[i][j - 1]`, the current `dp[i][j]` often depends on them.
- When operating "two swappable arrays", due to symmetry, we may need to use `dp[i - 1][j]` and `dp[i][j - 1]` at the same time.
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
@@ -83,7 +83,7 @@ This problem is quite difficult if you have not solved similar problems before.
After reading the above, do you feel that "dynamic programming" is not that difficult? Try to solve this problem. 🤗
-## Steps
+## Step by Step Solutions
1. Determine the **meaning** of the `dp[j]`
- `dp[j]` represents that by using the **first** `i` nums, the **number** of different **expressions** that you can build, which evaluates to `j`.
@@ -333,9 +333,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [494. Target Sum - LeetCode Best Practices](https://leetcoder.net/en/leetcode/494-target-sum).
+Original link: [494. Target Sum - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/494-target-sum).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/5-longest-palindromic-substring.md b/en/1-1000/5-longest-palindromic-substring.md
index bcc619c..f3161c9 100644
--- a/en/1-1000/5-longest-palindromic-substring.md
+++ b/en/1-1000/5-longest-palindromic-substring.md
@@ -1,6 +1,6 @@
-# 5. Longest Palindromic Substring - LeetCode Best Practices
+# 5. Longest Palindromic Substring - LeetCode Python/Java/C++/JS code
-Visit original link: [5. Longest Palindromic Substring - LeetCode Best Practices](https://leetcoder.net/en/leetcode/5-longest-palindromic-substring) for a better experience!
+Visit original link: [5. Longest Palindromic Substring - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/5-longest-palindromic-substring) for a better experience!
LeetCode link: [5. Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring), difficulty: **Medium**.
@@ -64,15 +64,15 @@ If we use brute-force and check whether for every start and end position a subst
#### "Dynamic programming" is divided into five steps
-1. Determine the meaning of each value of the array `dp`.
+1. Determine the **meaning** of each value of the array `dp`.
2. Initialize the value of the array `dp`.
-3. Fill in the `dp` grid data "in order" according to an example.
-4. Based on the `dp` grid data, derive the "recursive formula".
+3. Fill in the `dp` grid data **in order** according to an example.
+4. Based on the `dp` grid data, derive the **recursive formula**.
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
#### Detailed description of these five steps
-1. Determine the meaning of each value of the array `dp`.
+1. Determine the **meaning** of each value of the array `dp`.
- First determine whether `dp` is a one-dimensional array or a two-dimensional array. A `one-dimensional rolling array` means that the values of the array are overwritten at each iteration. Most of the time, using `one-dimensional rolling array` instead of `two-dimensional array` can simplify the code; but for some problems, such as operating "two swappable arrays", for the sake of ease of understanding, it is better to use `two-dimensional array`.
- Try to use the meaning of the `return value` required by the problem as the meaning of `dp[i]` (one-dimensional) or `dp[i][j]` (two-dimensional). It works about 60% of the time. If it doesn't work, try other meanings.
- Try to save more information in the design. Repeated information only needs to be saved once in a `dp[i]`.
@@ -80,14 +80,14 @@ If we use brute-force and check whether for every start and end position a subst
2. Initialize the value of the array `dp`. The value of `dp` involves two levels:
1. The length of `dp`. Usually: `condition array length plus 1` or `condition array length`.
2. The value of `dp[i]` or `dp[i][j]`. `dp[0]` or `dp[0][0]` sometimes requires special treatment.
-3. Fill in the `dp` grid data "in order" according to an example.
+3. Fill in the `dp` grid data **in order** according to an example.
- The "recursive formula" is the core of the "dynamic programming" algorithm. But the "recursive formula" is obscure. If you want to get it, you need to make a table and use data to inspire yourself.
- If the original example is not good enough, you need to redesign one yourself.
- According to the example, fill in the `dp` grid data "in order", which is very important because it determines the traversal order of the code.
- Most of the time, from left to right, from top to bottom. But sometimes it is necessary to traverse from right to left, from bottom to top, from the middle to the right (or left), such as the "palindrome" problems. Sometimes, it is necessary to traverse a line twice, first forward and then backward.
- When the order is determined correctly, the starting point is determined. Starting from the starting point, fill in the `dp` grid data "in order". This order is also the order in which the program processes.
- In this process, you will get inspiration to write a "recursive formula". If you can already derive the formula, you do not need to complete the grid.
-4. Based on the `dp` grid data, derive the "recursive formula".
+4. Based on the `dp` grid data, derive the **recursive formula**.
- There are three special positions to pay attention to: `dp[i - 1][j - 1]`, `dp[i - 1][j]` and `dp[i][j - 1]`, the current `dp[i][j]` often depends on them.
- When operating "two swappable arrays", due to symmetry, we may need to use `dp[i - 1][j]` and `dp[i][j - 1]` at the same time.
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
@@ -140,9 +140,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [5. Longest Palindromic Substring - LeetCode Best Practices](https://leetcoder.net/en/leetcode/5-longest-palindromic-substring).
+Original link: [5. Longest Palindromic Substring - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/5-longest-palindromic-substring).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/509-fibonacci-number.md b/en/1-1000/509-fibonacci-number.md
index 5cfd52b..2c60357 100644
--- a/en/1-1000/509-fibonacci-number.md
+++ b/en/1-1000/509-fibonacci-number.md
@@ -1,7 +1,11 @@
-# 509. Fibonacci Number
-LeetCode link: [509. Fibonacci Number](https://leetcode.com/problems/fibonacci-number/)
+# 509. Fibonacci Number - LeetCode Python/Java/C++/JS code
+
+Visit original link: [509. Fibonacci Number - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/509-fibonacci-number) for a better experience!
+
+LeetCode link: [509. Fibonacci Number](https://leetcode.com/problems/fibonacci-number), difficulty: **Easy**.
+
+## LeetCode description of "509. Fibonacci Number"
-## LeetCode problem description
The **Fibonacci numbers**, commonly denoted `F(n)` form a sequence, called the **Fibonacci sequence**, such that each number is the sum of the two preceding ones, starting from `0` and `1`. That is,
> F(0) = 0, F(1) = 1
@@ -9,44 +13,58 @@ The **Fibonacci numbers**, commonly denoted `F(n)` form a sequence, called the *
Given `n`, calculate `F(n)`.
-```
-------------------------------------------------------------------------
-[Example 1]
-
-Input: n = 2
-Output: 1
-Explanation: F(2) = F(1) + F(0) = 1 + 0 = 1.
-------------------------------------------------------------------------
-[Example 2]
-
-Input: n = 3
-Output: 2
-Explanation: F(3) = F(2) + F(1) = 1 + 1 = 2.
-------------------------------------------------------------------------
-[Example 3]
-
-Input: n = 4
-Output: 3
-Explanation: F(4) = F(3) + F(2) = 2 + 1 = 3.
-------------------------------------------------------------------------
-[Constraints]
+### [Example 1]
+
+**Input**: `n = 2`
+
+**Output**: `1`
+
+**Explanation**: `F(2) = F(1) + F(0) = 1 + 0 = 1`
+
+### [Example 2]
+
+**Input**: `n = 3`
+
+**Output**: `2`
+
+**Explanation**: `F(3) = F(2) + F(1) = 1 + 1 = 2`
+
+### [Example 3]
+
+**Input**: `n = 4`
+
+**Output**: `3`
+
+**Explanation**: `F(4) = F(3) + F(2) = 2 + 1 = 3`
+
+### [Constraints]
0 <= n <= 30
-------------------------------------------------------------------------
-```
-## Thoughts
-This problem can be solved using **Dynamic programming**.
+## Intuition 1
+
+
+
+## Pattern of "Recursion"
+
+Recursion is an important concept in computer science and mathematics, which refers to the method by which a function calls itself **directly or indirectly** in its definition.
+
+### The core idea of recursion
+
+- **Self-call**: A function calls itself during execution.
+- **Base case**: Equivalent to the termination condition. After reaching the base case, the result can be returned without recursive calls to prevent infinite loops.
+- **Recursive step**: The step by which the problem gradually approaches the "base case".
+
+## Complexity
-Detailed solutions will be given later, and now only the best practices in 4 to 7 languages are given.
+> If no Map is added to cache known results, the time complexity will rise to O( 2^N )
-### Complexity
-* Time: `O(n)`.
-* Space: `O(n)`.
+- Time complexity: `O(N)`.
+- Space complexity: `O(N)`.
## C#
-### Solution 1: Recursion
-```c#
+
+```csharp
public class Solution {
IDictionary numToFibNum = new Dictionary();
@@ -66,30 +84,180 @@ public class Solution {
}
```
-### Solution 2: Dynamic programming
-```c#
-public class Solution
-{
- public int Fib(int n)
- {
- if (n <= 1)
+## Python
+
+```python
+class Solution:
+ @cache
+ def fib(self, n: int) -> int:
+ if n <= 1:
+ return n
+
+ return self.fib(n - 1) + self.fib(n - 2)
+```
+
+## C++
+
+```cpp
+class Solution {
+public:
+ int fib(int n) {
+ if (n <= 1) {
return n;
+ }
- var dp = new int[n + 1];
- dp[1] = 1;
+ if (num_to_fib_num_.contains(n)) {
+ return num_to_fib_num_[n];
+ }
- for (var i = 2; i < dp.Length; i++)
- {
- dp[i] = dp[i - 1] + dp[i - 2];
+ num_to_fib_num_[n] = fib(n - 1) + fib(n - 2);
+
+ return num_to_fib_num_[n];
+ }
+
+private:
+ unordered_map num_to_fib_num_;
+};
+```
+
+## Java
+
+```java
+class Solution {
+ var numToFibNum = new HashMap();
+
+ public int fib(int n) {
+ if (n <= 1) {
+ return n;
}
- return dp[n];
+ if (numToFibNum.containsKey(n)) {
+ return numToFibNum.get(n);
+ }
+
+ numToFibNum.put(n, fib(n - 1) + fib(n - 2));
+
+ return numToFibNum.get(n);
}
}
```
-### Solution 3: Dynamic programming ('dp.length' is 2)
-```c#
+## JavaScript
+
+```javascript
+const numToFibNum = new Map()
+
+var fib = function (n) {
+ if (n <= 1) {
+ return n
+ }
+
+ if (numToFibNum.has(n)) {
+ return numToFibNum.get(n)
+ }
+
+ numToFibNum.set(n, fib(n - 1) + fib(n - 2))
+
+ return numToFibNum.get(n)
+};
+```
+
+## Go
+
+```go
+func fib(m int) int {
+ numToFibNum := map[int]int{}
+
+ var fibonacci func (int) int
+
+ fibonacci = func (n int) int {
+ if n <= 1 {
+ return n
+ }
+
+ if result, ok := numToFibNum[n]; ok {
+ return result
+ }
+
+ numToFibNum[n] = fibonacci(n - 1) + fibonacci(n - 2)
+ return numToFibNum[n]
+ }
+
+ return fibonacci(m)
+}
+```
+
+## Ruby
+
+```ruby
+def fib(n)
+ return n if n <= 1
+
+ @cache = {} if @cache.nil?
+
+ return @cache[n] if @cache.key?(n)
+
+ @cache[n] = fib(n - 1) + fib(n - 2)
+
+ @cache[n]
+end
+```
+
+## Other languages
+
+```java
+// Welcome to create a PR to complete the code of this language, thanks!
+```
+
+## Intuition 2
+
+
+
+## Pattern of "Dynamic Programming"
+
+"Dynamic Programming" requires the use of the `dp` array to store the results. The value of `dp[i][j]` can be converted from its previous (or multiple) values through a formula. Therefore, the value of `dp[i][j]` is derived step by step, and it is related to the previous `dp` record value.
+
+#### "Dynamic programming" is divided into five steps
+
+1. Determine the **meaning** of each value of the array `dp`.
+2. Initialize the value of the array `dp`.
+3. Fill in the `dp` grid data **in order** according to an example.
+4. Based on the `dp` grid data, derive the **recursive formula**.
+5. Write a program and print the `dp` array. If it is not as expected, adjust it.
+
+#### Detailed description of these five steps
+
+1. Determine the **meaning** of each value of the array `dp`.
+ - First determine whether `dp` is a one-dimensional array or a two-dimensional array. A `one-dimensional rolling array` means that the values of the array are overwritten at each iteration. Most of the time, using `one-dimensional rolling array` instead of `two-dimensional array` can simplify the code; but for some problems, such as operating "two swappable arrays", for the sake of ease of understanding, it is better to use `two-dimensional array`.
+ - Try to use the meaning of the `return value` required by the problem as the meaning of `dp[i]` (one-dimensional) or `dp[i][j]` (two-dimensional). It works about 60% of the time. If it doesn't work, try other meanings.
+ - Try to save more information in the design. Repeated information only needs to be saved once in a `dp[i]`.
+ - Use simplified meanings. If the problem can be solved with `boolean value`, don't use `numeric value`.
+2. Initialize the value of the array `dp`. The value of `dp` involves two levels:
+ 1. The length of `dp`. Usually: `condition array length plus 1` or `condition array length`.
+ 2. The value of `dp[i]` or `dp[i][j]`. `dp[0]` or `dp[0][0]` sometimes requires special treatment.
+3. Fill in the `dp` grid data **in order** according to an example.
+ - The "recursive formula" is the core of the "dynamic programming" algorithm. But the "recursive formula" is obscure. If you want to get it, you need to make a table and use data to inspire yourself.
+ - If the original example is not good enough, you need to redesign one yourself.
+ - According to the example, fill in the `dp` grid data "in order", which is very important because it determines the traversal order of the code.
+ - Most of the time, from left to right, from top to bottom. But sometimes it is necessary to traverse from right to left, from bottom to top, from the middle to the right (or left), such as the "palindrome" problems. Sometimes, it is necessary to traverse a line twice, first forward and then backward.
+ - When the order is determined correctly, the starting point is determined. Starting from the starting point, fill in the `dp` grid data "in order". This order is also the order in which the program processes.
+ - In this process, you will get inspiration to write a "recursive formula". If you can already derive the formula, you do not need to complete the grid.
+4. Based on the `dp` grid data, derive the **recursive formula**.
+ - There are three special positions to pay attention to: `dp[i - 1][j - 1]`, `dp[i - 1][j]` and `dp[i][j - 1]`, the current `dp[i][j]` often depends on them.
+ - When operating "two swappable arrays", due to symmetry, we may need to use `dp[i - 1][j]` and `dp[i][j - 1]` at the same time.
+5. Write a program and print the `dp` array. If it is not as expected, adjust it.
+ - Focus on analyzing those values that are not as expected.
+
+After reading the above, do you feel that "dynamic programming" is not that difficult? Try to solve this problem. 🤗
+
+## Complexity
+
+- Time complexity: `O(N)`.
+- Space complexity: `O(N)`.
+
+## C#
+
+```csharp
public class Solution
{
public int Fib(int n)
@@ -97,34 +265,21 @@ public class Solution
if (n <= 1)
return n;
- int[] dp = [0, 1];
+ var dp = new int[n + 1];
+ dp[1] = 1;
- for (var i = 2; i <= n; i++)
+ for (var i = 2; i < dp.Length; i++)
{
- var dc = (int[])dp.Clone();
-
- dp[0] = dc[1];
- dp[1] = dc[0] + dc[1];
+ dp[i] = dp[i - 1] + dp[i - 2];
}
- return dp[1];
+ return dp[n];
}
}
```
## Python
-### Solution 1: Recursion
-```python
-class Solution:
- @cache
- def fib(self, n: int) -> int:
- if n <= 1:
- return n
-
- return self.fib(n - 1) + self.fib(n - 2)
-```
-### Solution 2: Dynamic programming
```python
class Solution:
def fib(self, n: int) -> int:
@@ -140,26 +295,8 @@ class Solution:
return dp[-1]
```
-### Solution 3: Dynamic programming ('dp.length' is 2)
-```python
-class Solution:
- def fib(self, n: int) -> int:
- if n == 0:
- return 0
-
- dp = [0, 1]
-
- for i in range(2, n + 1):
- dc = dp.copy()
-
- dp[0] = dc[1]
- dp[1] = dc[0] + dc[1]
-
- return dp[1]
-```
-
## C++
-### Solution 1: Recursion
+
```cpp
class Solution {
public:
@@ -168,54 +305,161 @@ public:
return n;
}
- if (num_to_fib_num_.contains(n)) {
- return num_to_fib_num_[n];
- }
+ auto dp = vector(n + 1);
+ dp[1] = 1;
- num_to_fib_num_[n] = fib(n - 1) + fib(n - 2);
+ for (auto i = 2; i < dp.size(); i++) {
+ dp[i] = dp[i - 1] + dp[i - 2];
+ }
- return num_to_fib_num_[n];
+ return dp[n];
}
-
-private:
- unordered_map num_to_fib_num_;
};
```
-### Solution 2: Dynamic programming
-```c++
+## Java
+
+```java
class Solution {
-public:
- int fib(int n) {
+ public int fib(int n) {
if (n <= 1) {
return n;
}
- auto dp = vector(n + 1);
+ var dp = new int[n + 1];
dp[1] = 1;
- for (auto i = 2; i < dp.size(); i++) {
+ for (var i = 2; i < dp.length; i++) {
dp[i] = dp[i - 1] + dp[i - 2];
}
return dp[n];
}
+}
+```
+
+## JavaScript
+
+```javascript
+var fib = function (n) {
+ if (n <= 1) {
+ return n
+ }
+
+ const dp = Array(n + 1).fill(0)
+ dp[1] = 1
+
+ for (let i = 2; i < dp.length; i++) {
+ dp[i] = dp[i - 1] + dp[i - 2]
+ }
+
+ return dp[n]
};
```
-### Solution 3: Dynamic programming ('dp.length' is 2)
-```c++
-class Solution {
-public:
- int fib(int n) {
- if (n <= 1) {
+## Go
+
+```go
+func fib(n int) int {
+ if n == 0 {
+ return 0
+ }
+
+ dp := make([]int, n + 1)
+ dp[1] = 1
+
+ for i := 2; i <= n; i++ {
+ dp[i] = dp[i - 2] + dp[i - 1]
+ }
+
+ return dp[n]
+}
+```
+
+## Ruby
+
+```ruby
+def fib(n)
+ return 0 if n == 0
+
+ dp = Array.new(n + 1, 0)
+ dp[1] = 1
+
+ (2...dp.size).each do |i|
+ dp[i] = dp[i - 1] + dp[i - 2]
+ end
+
+ dp[-1]
+end
+```
+
+## Other languages
+
+```java
+// Welcome to create a PR to complete the code of this language, thanks!
+```
+
+## Intuition 3
+
+
+
+## Pattern of "Dynamic Programming"
+
+"Dynamic Programming" requires the use of the `dp` array to store the results. The value of `dp[i][j]` can be converted from its previous (or multiple) values through a formula. Therefore, the value of `dp[i][j]` is derived step by step, and it is related to the previous `dp` record value.
+
+#### "Dynamic programming" is divided into five steps
+
+1. Determine the **meaning** of each value of the array `dp`.
+2. Initialize the value of the array `dp`.
+3. Fill in the `dp` grid data **in order** according to an example.
+4. Based on the `dp` grid data, derive the **recursive formula**.
+5. Write a program and print the `dp` array. If it is not as expected, adjust it.
+
+#### Detailed description of these five steps
+
+1. Determine the **meaning** of each value of the array `dp`.
+ - First determine whether `dp` is a one-dimensional array or a two-dimensional array. A `one-dimensional rolling array` means that the values of the array are overwritten at each iteration. Most of the time, using `one-dimensional rolling array` instead of `two-dimensional array` can simplify the code; but for some problems, such as operating "two swappable arrays", for the sake of ease of understanding, it is better to use `two-dimensional array`.
+ - Try to use the meaning of the `return value` required by the problem as the meaning of `dp[i]` (one-dimensional) or `dp[i][j]` (two-dimensional). It works about 60% of the time. If it doesn't work, try other meanings.
+ - Try to save more information in the design. Repeated information only needs to be saved once in a `dp[i]`.
+ - Use simplified meanings. If the problem can be solved with `boolean value`, don't use `numeric value`.
+2. Initialize the value of the array `dp`. The value of `dp` involves two levels:
+ 1. The length of `dp`. Usually: `condition array length plus 1` or `condition array length`.
+ 2. The value of `dp[i]` or `dp[i][j]`. `dp[0]` or `dp[0][0]` sometimes requires special treatment.
+3. Fill in the `dp` grid data **in order** according to an example.
+ - The "recursive formula" is the core of the "dynamic programming" algorithm. But the "recursive formula" is obscure. If you want to get it, you need to make a table and use data to inspire yourself.
+ - If the original example is not good enough, you need to redesign one yourself.
+ - According to the example, fill in the `dp` grid data "in order", which is very important because it determines the traversal order of the code.
+ - Most of the time, from left to right, from top to bottom. But sometimes it is necessary to traverse from right to left, from bottom to top, from the middle to the right (or left), such as the "palindrome" problems. Sometimes, it is necessary to traverse a line twice, first forward and then backward.
+ - When the order is determined correctly, the starting point is determined. Starting from the starting point, fill in the `dp` grid data "in order". This order is also the order in which the program processes.
+ - In this process, you will get inspiration to write a "recursive formula". If you can already derive the formula, you do not need to complete the grid.
+4. Based on the `dp` grid data, derive the **recursive formula**.
+ - There are three special positions to pay attention to: `dp[i - 1][j - 1]`, `dp[i - 1][j]` and `dp[i][j - 1]`, the current `dp[i][j]` often depends on them.
+ - When operating "two swappable arrays", due to symmetry, we may need to use `dp[i - 1][j]` and `dp[i][j - 1]` at the same time.
+5. Write a program and print the `dp` array. If it is not as expected, adjust it.
+ - Focus on analyzing those values that are not as expected.
+
+After reading the above, do you feel that "dynamic programming" is not that difficult? Try to solve this problem. 🤗
+
+## Complexity
+
+- Time complexity: `O(N)`.
+- Space complexity: `O(1)`.
+
+## C#
+
+```csharp
+public class Solution
+{
+ public int Fib(int n)
+ {
+ if (n <= 1)
return n;
- }
- vector dp = {0, 1};
+ int[] dp = [0, 1];
- for (auto i = 2; i <= n; i++) {
- auto dc = dp;
+ for (var i = 2; i <= n; i++)
+ {
+ var dc = (int[])dp.Clone();
dp[0] = dc[1];
dp[1] = dc[0] + dc[1];
@@ -223,52 +467,54 @@ public:
return dp[1];
}
-};
+}
```
-## Java
-### Solution 1: Recursion
-```java
-class Solution {
- var numToFibNum = new HashMap();
+## Python
- public int fib(int n) {
- if (n <= 1) {
- return n;
- }
+```python
+class Solution:
+ def fib(self, n: int) -> int:
+ if n == 0:
+ return 0
- if (numToFibNum.containsKey(n)) {
- return numToFibNum.get(n);
- }
+ dp = [0, 1]
- numToFibNum.put(n, fib(n - 1) + fib(n - 2));
+ for i in range(2, n + 1):
+ dc = dp.copy()
- return numToFibNum.get(n);
- }
-}
+ dp[0] = dc[1]
+ dp[1] = dc[0] + dc[1]
+
+ return dp[1]
```
-### Solution 2: Dynamic programming
-```java
+## C++
+
+```cpp
class Solution {
- public int fib(int n) {
+public:
+ int fib(int n) {
if (n <= 1) {
return n;
}
- var dp = new int[n + 1];
- dp[1] = 1;
+ vector dp = {0, 1};
- for (var i = 2; i < dp.length; i++) {
- dp[i] = dp[i - 1] + dp[i - 2];
+ for (auto i = 2; i <= n; i++) {
+ auto dc = dp;
+
+ dp[0] = dc[1];
+ dp[1] = dc[0] + dc[1];
}
- return dp[n];
+ return dp[1];
}
-}
+};
```
-### Solution 3: Dynamic programming ('dp.length' is 2)
+## Java
+
```java
class Solution {
public int fib(int n) {
@@ -291,44 +537,7 @@ class Solution {
```
## JavaScript
-### Solution 1: Recursion
-```javascript
-const numToFibNum = new Map()
-var fib = function (n) {
- if (n <= 1) {
- return n
- }
-
- if (numToFibNum.has(n)) {
- return numToFibNum.get(n)
- }
-
- numToFibNum.set(n, fib(n - 1) + fib(n - 2))
-
- return numToFibNum.get(n)
-};
-```
-
-### Solution 2: Dynamic programming
-```javascript
-var fib = function (n) {
- if (n <= 1) {
- return n
- }
-
- const dp = Array(n + 1).fill(0)
- dp[1] = 1
-
- for (let i = 2; i < dp.length; i++) {
- dp[i] = dp[i - 1] + dp[i - 2]
- }
-
- return dp[n]
-};
-```
-
-### Solution 3: Dynamic programming ('dp.length' is 2)
```javascript
var fib = function (n) {
if (n <= 1) {
@@ -349,49 +558,7 @@ var fib = function (n) {
```
## Go
-### Solution 1: Recursion
-```go
-func fib(m int) int {
- numToFibNum := map[int]int{}
-
- var fibonacci func (int) int
-
- fibonacci = func (n int) int {
- if n <= 1 {
- return n
- }
- if result, ok := numToFibNum[n]; ok {
- return result
- }
-
- numToFibNum[n] = fibonacci(n - 1) + fibonacci(n - 2)
- return numToFibNum[n]
- }
-
- return fibonacci(m)
-}
-```
-
-### Solution 2: Dynamic programming
-```go
-func fib(n int) int {
- if n == 0 {
- return 0
- }
-
- dp := make([]int, n + 1)
- dp[1] = 1
-
- for i := 2; i <= n; i++ {
- dp[i] = dp[i - 2] + dp[i - 1]
- }
-
- return dp[n]
-}
-```
-
-### Solution 3: Dynamic programming ('dp.length' is 2)
```go
func fib(n int) int {
if n == 0 {
@@ -412,38 +579,7 @@ func fib(n int) int {
```
## Ruby
-### Solution 1: Recursion
-```ruby
-def fib(n)
- return n if n <= 1
-
- @cache = {} if @cache.nil?
-
- return @cache[n] if @cache.key?(n)
-
- @cache[n] = fib(n - 1) + fib(n - 2)
-
- @cache[n]
-end
-```
-
-### Solution 2: Dynamic programming
-```ruby
-def fib(n)
- return 0 if n == 0
-
- dp = Array.new(n + 1, 0)
- dp[1] = 1
-
- (2...dp.size).each do |i|
- dp[i] = dp[i - 1] + dp[i - 2]
- end
-
- dp[-1]
-end
-```
-### Solution 3: Dynamic programming ('dp.length' is 2)
```ruby
def fib(n)
return 0 if n == 0
@@ -461,12 +597,15 @@ def fib(n)
end
```
-## Rust
-```rust
-// Welcome to create a PR to complete the code of this language, thanks!
-```
-
## Other languages
-```
+
+```java
// Welcome to create a PR to complete the code of this language, thanks!
```
+
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+
+Original link: [509. Fibonacci Number - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/509-fibonacci-number).
+
+GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
+
diff --git a/en/1-1000/53-maximum-subarray.md b/en/1-1000/53-maximum-subarray.md
index fbce69f..e58758b 100644
--- a/en/1-1000/53-maximum-subarray.md
+++ b/en/1-1000/53-maximum-subarray.md
@@ -1,6 +1,6 @@
-# 53. Maximum Subarray - LeetCode Best Practices
+# 53. Maximum Subarray - LeetCode Python/Java/C++/JS code
-Visit original link: [53. Maximum Subarray - LeetCode Best Practices](https://leetcoder.net/en/leetcode/53-maximum-subarray) for a better experience!
+Visit original link: [53. Maximum Subarray - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/53-maximum-subarray) for a better experience!
LeetCode link: [53. Maximum Subarray](https://leetcode.com/problems/maximum-subarray), difficulty: **Medium**.
@@ -57,15 +57,15 @@ Given an integer array `nums`, find the `subarray` with the largest sum, and ret
#### "Dynamic programming" is divided into five steps
-1. Determine the meaning of each value of the array `dp`.
+1. Determine the **meaning** of each value of the array `dp`.
2. Initialize the value of the array `dp`.
-3. Fill in the `dp` grid data "in order" according to an example.
-4. Based on the `dp` grid data, derive the "recursive formula".
+3. Fill in the `dp` grid data **in order** according to an example.
+4. Based on the `dp` grid data, derive the **recursive formula**.
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
#### Detailed description of these five steps
-1. Determine the meaning of each value of the array `dp`.
+1. Determine the **meaning** of each value of the array `dp`.
- First determine whether `dp` is a one-dimensional array or a two-dimensional array. A `one-dimensional rolling array` means that the values of the array are overwritten at each iteration. Most of the time, using `one-dimensional rolling array` instead of `two-dimensional array` can simplify the code; but for some problems, such as operating "two swappable arrays", for the sake of ease of understanding, it is better to use `two-dimensional array`.
- Try to use the meaning of the `return value` required by the problem as the meaning of `dp[i]` (one-dimensional) or `dp[i][j]` (two-dimensional). It works about 60% of the time. If it doesn't work, try other meanings.
- Try to save more information in the design. Repeated information only needs to be saved once in a `dp[i]`.
@@ -73,14 +73,14 @@ Given an integer array `nums`, find the `subarray` with the largest sum, and ret
2. Initialize the value of the array `dp`. The value of `dp` involves two levels:
1. The length of `dp`. Usually: `condition array length plus 1` or `condition array length`.
2. The value of `dp[i]` or `dp[i][j]`. `dp[0]` or `dp[0][0]` sometimes requires special treatment.
-3. Fill in the `dp` grid data "in order" according to an example.
+3. Fill in the `dp` grid data **in order** according to an example.
- The "recursive formula" is the core of the "dynamic programming" algorithm. But the "recursive formula" is obscure. If you want to get it, you need to make a table and use data to inspire yourself.
- If the original example is not good enough, you need to redesign one yourself.
- According to the example, fill in the `dp` grid data "in order", which is very important because it determines the traversal order of the code.
- Most of the time, from left to right, from top to bottom. But sometimes it is necessary to traverse from right to left, from bottom to top, from the middle to the right (or left), such as the "palindrome" problems. Sometimes, it is necessary to traverse a line twice, first forward and then backward.
- When the order is determined correctly, the starting point is determined. Starting from the starting point, fill in the `dp` grid data "in order". This order is also the order in which the program processes.
- In this process, you will get inspiration to write a "recursive formula". If you can already derive the formula, you do not need to complete the grid.
-4. Based on the `dp` grid data, derive the "recursive formula".
+4. Based on the `dp` grid data, derive the **recursive formula**.
- There are three special positions to pay attention to: `dp[i - 1][j - 1]`, `dp[i - 1][j]` and `dp[i][j - 1]`, the current `dp[i][j]` often depends on them.
- When operating "two swappable arrays", due to symmetry, we may need to use `dp[i - 1][j]` and `dp[i][j - 1]` at the same time.
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
@@ -88,7 +88,7 @@ Given an integer array `nums`, find the `subarray` with the largest sum, and ret
After reading the above, do you feel that "dynamic programming" is not that difficult? Try to solve this problem. 🤗
-## Steps
+## Step by Step Solutions
1. Determine the **meaning** of the `dp[i]`
- Imagine that `dp[i]` represents the `largest sum` at index `i`. Is this okay?
@@ -384,9 +384,9 @@ class Solution {
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [53. Maximum Subarray - LeetCode Best Practices](https://leetcoder.net/en/leetcode/53-maximum-subarray).
+Original link: [53. Maximum Subarray - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/53-maximum-subarray).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/541-reverse-string-ii.md b/en/1-1000/541-reverse-string-ii.md
index 6718b03..a153291 100644
--- a/en/1-1000/541-reverse-string-ii.md
+++ b/en/1-1000/541-reverse-string-ii.md
@@ -1,6 +1,6 @@
-# 541. Reverse String II - LeetCode Best Practices
+# 541. Reverse String II - LeetCode Python/Java/C++/JS code
-Visit original link: [541. Reverse String II - LeetCode Best Practices](https://leetcoder.net/en/leetcode/541-reverse-string-ii) for a better experience!
+Visit original link: [541. Reverse String II - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/541-reverse-string-ii) for a better experience!
LeetCode link: [541. Reverse String II](https://leetcode.com/problems/reverse-string-ii), difficulty: **Easy**.
@@ -35,7 +35,7 @@ Given a string `s` and an integer `k`, reverse the first `k` characters for ever
2. In the loop, it is more convenient to use `k` as the step value rather than `2k`, because if `2k` is used, `k` must still be used for judgment.
3. It is required to reverse only the first `k` characters of each `2k` characters, so a `boolean` variable `should_reverse` is needed as a judgment condition for whether to reverse.
-## Steps
+## Step by Step Solutions
1. Use a new string `result` as the return value. In the loop, the step value is `k`.
@@ -276,9 +276,9 @@ func reverseStr(s string, k int) string {
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [541. Reverse String II - LeetCode Best Practices](https://leetcoder.net/en/leetcode/541-reverse-string-ii).
+Original link: [541. Reverse String II - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/541-reverse-string-ii).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/583-delete-operation-for-two-strings.md b/en/1-1000/583-delete-operation-for-two-strings.md
index f728dbf..3bdb645 100644
--- a/en/1-1000/583-delete-operation-for-two-strings.md
+++ b/en/1-1000/583-delete-operation-for-two-strings.md
@@ -1,6 +1,6 @@
-# 583. Delete Operation for Two Strings - LeetCode Best Practices
+# 583. Delete Operation for Two Strings - LeetCode Python/Java/C++/JS code
-Visit original link: [583. Delete Operation for Two Strings - LeetCode Best Practices](https://leetcoder.net/en/leetcode/583-delete-operation-for-two-strings) for a better experience!
+Visit original link: [583. Delete Operation for Two Strings - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/583-delete-operation-for-two-strings) for a better experience!
LeetCode link: [583. Delete Operation for Two Strings](https://leetcode.com/problems/delete-operation-for-two-strings), difficulty: **Medium**.
@@ -43,15 +43,15 @@ After doing similar questions many times, we will form the intuition of using `t
#### "Dynamic programming" is divided into five steps
-1. Determine the meaning of each value of the array `dp`.
+1. Determine the **meaning** of each value of the array `dp`.
2. Initialize the value of the array `dp`.
-3. Fill in the `dp` grid data "in order" according to an example.
-4. Based on the `dp` grid data, derive the "recursive formula".
+3. Fill in the `dp` grid data **in order** according to an example.
+4. Based on the `dp` grid data, derive the **recursive formula**.
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
#### Detailed description of these five steps
-1. Determine the meaning of each value of the array `dp`.
+1. Determine the **meaning** of each value of the array `dp`.
- First determine whether `dp` is a one-dimensional array or a two-dimensional array. A `one-dimensional rolling array` means that the values of the array are overwritten at each iteration. Most of the time, using `one-dimensional rolling array` instead of `two-dimensional array` can simplify the code; but for some problems, such as operating "two swappable arrays", for the sake of ease of understanding, it is better to use `two-dimensional array`.
- Try to use the meaning of the `return value` required by the problem as the meaning of `dp[i]` (one-dimensional) or `dp[i][j]` (two-dimensional). It works about 60% of the time. If it doesn't work, try other meanings.
- Try to save more information in the design. Repeated information only needs to be saved once in a `dp[i]`.
@@ -59,14 +59,14 @@ After doing similar questions many times, we will form the intuition of using `t
2. Initialize the value of the array `dp`. The value of `dp` involves two levels:
1. The length of `dp`. Usually: `condition array length plus 1` or `condition array length`.
2. The value of `dp[i]` or `dp[i][j]`. `dp[0]` or `dp[0][0]` sometimes requires special treatment.
-3. Fill in the `dp` grid data "in order" according to an example.
+3. Fill in the `dp` grid data **in order** according to an example.
- The "recursive formula" is the core of the "dynamic programming" algorithm. But the "recursive formula" is obscure. If you want to get it, you need to make a table and use data to inspire yourself.
- If the original example is not good enough, you need to redesign one yourself.
- According to the example, fill in the `dp` grid data "in order", which is very important because it determines the traversal order of the code.
- Most of the time, from left to right, from top to bottom. But sometimes it is necessary to traverse from right to left, from bottom to top, from the middle to the right (or left), such as the "palindrome" problems. Sometimes, it is necessary to traverse a line twice, first forward and then backward.
- When the order is determined correctly, the starting point is determined. Starting from the starting point, fill in the `dp` grid data "in order". This order is also the order in which the program processes.
- In this process, you will get inspiration to write a "recursive formula". If you can already derive the formula, you do not need to complete the grid.
-4. Based on the `dp` grid data, derive the "recursive formula".
+4. Based on the `dp` grid data, derive the **recursive formula**.
- There are three special positions to pay attention to: `dp[i - 1][j - 1]`, `dp[i - 1][j]` and `dp[i][j - 1]`, the current `dp[i][j]` often depends on them.
- When operating "two swappable arrays", due to symmetry, we may need to use `dp[i - 1][j]` and `dp[i][j - 1]` at the same time.
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
@@ -74,7 +74,7 @@ After doing similar questions many times, we will form the intuition of using `t
After reading the above, do you feel that "dynamic programming" is not that difficult? Try to solve this problem. 🤗
-## Steps
+## Step by Step Solutions
1. Determine the **meaning** of the `dp[i][j]`.
- `dp[i][j]` represents the **minimum** number of steps required to make `word1`'s first `i` letters and `word2`'s first `j` letters the same.
@@ -329,9 +329,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [583. Delete Operation for Two Strings - LeetCode Best Practices](https://leetcoder.net/en/leetcode/583-delete-operation-for-two-strings).
+Original link: [583. Delete Operation for Two Strings - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/583-delete-operation-for-two-strings).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/59-spiral-matrix-ii.md b/en/1-1000/59-spiral-matrix-ii.md
index 70eaf29..19d4225 100644
--- a/en/1-1000/59-spiral-matrix-ii.md
+++ b/en/1-1000/59-spiral-matrix-ii.md
@@ -1,6 +1,6 @@
-# 59. Spiral Matrix II - LeetCode Best Practices
+# 59. Spiral Matrix II - LeetCode Python/Java/C++/JS code
-Visit original link: [59. Spiral Matrix II - LeetCode Best Practices](https://leetcoder.net/en/leetcode/59-spiral-matrix-ii) for a better experience!
+Visit original link: [59. Spiral Matrix II - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/59-spiral-matrix-ii) for a better experience!
LeetCode link: [59. Spiral Matrix II](https://leetcode.com/problems/spiral-matrix-ii), difficulty: **Medium**.
@@ -32,7 +32,7 @@ Given a positive integer `n`, generate an `n x n` matrix filled with elements fr
- You can write a method `get_increment(i, j)`, which is specifically used to get the change between the next position and the current position.
-## Steps
+## Step by Step Solutions
1. Initialize `increments` and `increment_index`:
@@ -408,9 +408,9 @@ private:
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [59. Spiral Matrix II - LeetCode Best Practices](https://leetcoder.net/en/leetcode/59-spiral-matrix-ii).
+Original link: [59. Spiral Matrix II - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/59-spiral-matrix-ii).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/704-binary-search.md b/en/1-1000/704-binary-search.md
index e9595ef..7213699 100644
--- a/en/1-1000/704-binary-search.md
+++ b/en/1-1000/704-binary-search.md
@@ -1,6 +1,6 @@
-# 704. Binary Search - LeetCode Best Practices
+# 704. Binary Search - LeetCode Python/Java/C++/JS code
-Visit original link: [704. Binary Search - LeetCode Best Practices](https://leetcoder.net/en/leetcode/704-binary-search) for a better experience!
+Visit original link: [704. Binary Search - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/704-binary-search) for a better experience!
LeetCode link: [704. Binary Search](https://leetcode.com/problems/binary-search), difficulty: **Easy**.
@@ -37,7 +37,7 @@ You must write an algorithm with `O(log n)` runtime complexity.
Because it is an already sorted array, by using the middle value for comparison, half of the numbers can be eliminated each time.
-## Steps
+## Step by Step Solutions
The fastest and easiest way is to use the three indices `left`, `right`, and `middle`.
If `nums[middle] > target`, then `right = middle - 1`, otherwise, `left = middle + 1`.
@@ -237,9 +237,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [704. Binary Search - LeetCode Best Practices](https://leetcoder.net/en/leetcode/704-binary-search).
+Original link: [704. Binary Search - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/704-binary-search).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/707-design-linked-list.md b/en/1-1000/707-design-linked-list.md
index 393c8ce..108d272 100644
--- a/en/1-1000/707-design-linked-list.md
+++ b/en/1-1000/707-design-linked-list.md
@@ -1,6 +1,6 @@
-# 707. Design Linked List - LeetCode Best Practices
+# 707. Design Linked List - LeetCode Python/Java/C++/JS code
-Visit original link: [707. Design Linked List - LeetCode Best Practices](https://leetcoder.net/en/leetcode/707-design-linked-list) for a better experience!
+Visit original link: [707. Design Linked List - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/707-design-linked-list) for a better experience!
LeetCode link: [707. Design Linked List](https://leetcode.com/problems/design-linked-list), difficulty: **Medium**.
@@ -633,9 +633,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [707. Design Linked List - LeetCode Best Practices](https://leetcoder.net/en/leetcode/707-design-linked-list).
+Original link: [707. Design Linked List - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/707-design-linked-list).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/72-edit-distance.md b/en/1-1000/72-edit-distance.md
index ebedd9f..ed8f394 100644
--- a/en/1-1000/72-edit-distance.md
+++ b/en/1-1000/72-edit-distance.md
@@ -1,136 +1,182 @@
-# 72. Edit Distance (Dynamic Programming Solution)
-LeetCode link: [72. Edit Distance](https://leetcode.com/problems/edit-distance/)
+# 72. Edit Distance - LeetCode Python/Java/C++/JS code
-## LeetCode problem description
-> Given two strings `word1` and `word2`, return the **minimum** number of operations required to convert `word1` to `word2`.
+Visit original link: [72. Edit Distance - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/72-edit-distance) for a better experience!
+
+LeetCode link: [72. Edit Distance](https://leetcode.com/problems/edit-distance), difficulty: **Medium**.
+
+## LeetCode description of "72. Edit Distance"
+
+Given two strings `word1` and `word2`, return the **minimum** number of operations required to convert `word1` to `word2`.
You have the following three operations permitted on a word:
+
- Insert a character
- Delete a character
- Replace a character
-```
-Example 1:
+### [Example 1]
+
+**Input**: `word1 = "horse", word2 = "ros"`
+
+**Output**: `3`
+
+**Explanation**:
-Input: word1 = "horse", word2 = "ros"
-Output: 3
+horse -> rorse (replace 'h' with 'r')
+rorse -> rose (remove 'r')
+rose -> ros (remove 'e')
-Explanation:
-horse -> rorse (replace 'h' with 'r')
-rorse -> rose (remove 'r')
-rose -> ros (remove 'e')
--------------------------------------------------------
-Example 2:
+### [Example 2]
-Input: word1 = "intention", word2 = "execution"
-Output: 5
+**Input**: `word1 = "intention", word2 = "execution"`
-Explanation:
-intention -> inention (remove 't')
-inention -> enention (replace 'i' with 'e')
-enention -> exention (replace 'n' with 'x')
-exention -> exection (replace 'n' with 'c')
-exection -> execution (insert 'u')
--------------------------------------------------------
+**Output**: `5`
-Constraints:
+**Explanation**:
-1. 0 <= word1.length, word2.length <= 500
+intention -> inention (remove 't')
+inention -> enention (replace 'i' with 'e')
+enention -> exention (replace 'n' with 'x')
+exention -> exection (replace 'n' with 'c')
+exection -> execution (insert 'u')
+
+
+### [Constraints]
+
+1. `0 <= word1.length, word2.length <= 500`
2. `word1` and `word2` consist of lowercase English letters.
-```
-## Thoughts
-* It is a question of comparing two strings. After doing similar questions many times, we will develop an intuition to use dynamic programming with two-dimensional arrays.
-
-### Common steps in dynamic programming
-These five steps are a pattern for solving `dynamic programming` problems.
-
-1. Determine the **meaning** of the `dp[i][j]`
- * Since there are two strings, we can use two-dimensional arrays as the default option.
- * At first, try to use the problem's `return` value as the value of `dp[i][j]` to determine the meaning of `dp[i][j]`. If it doesn't work, try another way.
- * `dp[i][j]` represents the **minimum** number of operations required to convert `word1`'s first `i` letters to `word2`'s first `j` letters.
- * `dp[i][j]` is an integer.
-2. Determine the `dp` array's initial value
- * Use an example:
- ```
- After initialization, the 'dp' array would be:
- # r o s
- # 0 1 2 3 # dp[0]
- # h 1 0 0 0
- # o 2 0 0 0
- # r 3 0 0 0
- # s 4 0 0 0
- # e 5 0 0 0
- ```
- * `dp[i][0] = i`, because `dp[i][0]` represents the empty string, and the number of operations is just the number of chars to be deleted.
- * `dp[0][j] = j`, the reason is the same as the previous line, just viewed from the opposite angle: convert `word2` to `word1`.
-
-3. Determine the `dp` array's recurrence formula
- * Try to complete the `dp` grid. In the process, you will get inspiration to derive the formula.
- ```
- 1. Convert `h` to `ros`.
- # r o s
- # 0 1 2 3
- # h 1 1 2 3 # dp[1]
- ```
- ```
- 2. Convert `ho` to `ros`.
- # r o s
- # 0 1 2 3
- # h 1 1 2 3
- # o 2 2 1 2
- ```
- ```
- 3. Convert `hor` to `ros`.
- # r o s
- # 0 1 2 3
- # h 1 1 2 3
- # o 2 2 1 2
- # r 3 2 2 2
- ```
- ```
- 4. Convert `hors` to `ros`.
- # r o s
- # 0 1 2 3
- # h 1 1 2 3
- # o 2 2 1 2
- # r 3 2 2 2
- # s 4 3 3 2
- ```
- ```
- 5. Convert `horse` to `ros`.
- # r o s
- # 0 1 2 3
- # h 1 1 2 3
- # o 2 2 1 2
- # r 3 2 2 2
- # s 4 3 3 2
- # e 5 4 4 3 # dp[5]
- ```
- * When analyzing the sample `dp` grid, remember there are three important points which you should pay special attention to: `dp[i - 1][j - 1]`, `dp[i - 1][j]` and `dp[i][j - 1]`. The current `dp[i][j]` often depends on them.
- * If the question is also true in reverse (swap `word1` and `word2`), and we need to use `dp[i - 1][j]` or `dp[i][j - 1]`, then we probably need to use both of them.
- * We can derive the `Recurrence Formula`:
- ```python
- if word1[i - 1] == word2[j - 1]
- dp[i][j] = dp[i - 1][j - 1]
- else
- dp[i][j] = min(
- dp[i - 1][j - 1],
- dp[i - 1][j],
- dp[i][j - 1],
- ) + 1
- ```
-4. Determine the `dp` array's traversal order
- * `dp[i][j]` depends on `dp[i - 1][j - 1]`, `dp[i - 1][j]` and `dp[i][j - 1]`, so we should traverse the `dp` array from top to bottom, then from left to right.
-5. Check the `dp` array's value
- * Print the `dp` to see if it is as expected.
-
-### Complexity
-* Time: `O(n * m)`.
-* Space: `O(n * m)`.
+## Intuition
+
+It is a question of comparing two strings. After doing similar questions many times, we will develop an intuition to use Dynamic Programming with *two-dimensional* arrays.
+
+## Pattern of "Dynamic Programming"
+
+"Dynamic Programming" requires the use of the `dp` array to store the results. The value of `dp[i][j]` can be converted from its previous (or multiple) values through a formula. Therefore, the value of `dp[i][j]` is derived step by step, and it is related to the previous `dp` record value.
+
+#### "Dynamic programming" is divided into five steps
+
+1. Determine the **meaning** of each value of the array `dp`.
+2. Initialize the value of the array `dp`.
+3. Fill in the `dp` grid data **in order** according to an example.
+4. Based on the `dp` grid data, derive the **recursive formula**.
+5. Write a program and print the `dp` array. If it is not as expected, adjust it.
+
+#### Detailed description of these five steps
+
+1. Determine the **meaning** of each value of the array `dp`.
+ - First determine whether `dp` is a one-dimensional array or a two-dimensional array. A `one-dimensional rolling array` means that the values of the array are overwritten at each iteration. Most of the time, using `one-dimensional rolling array` instead of `two-dimensional array` can simplify the code; but for some problems, such as operating "two swappable arrays", for the sake of ease of understanding, it is better to use `two-dimensional array`.
+ - Try to use the meaning of the `return value` required by the problem as the meaning of `dp[i]` (one-dimensional) or `dp[i][j]` (two-dimensional). It works about 60% of the time. If it doesn't work, try other meanings.
+ - Try to save more information in the design. Repeated information only needs to be saved once in a `dp[i]`.
+ - Use simplified meanings. If the problem can be solved with `boolean value`, don't use `numeric value`.
+2. Initialize the value of the array `dp`. The value of `dp` involves two levels:
+ 1. The length of `dp`. Usually: `condition array length plus 1` or `condition array length`.
+ 2. The value of `dp[i]` or `dp[i][j]`. `dp[0]` or `dp[0][0]` sometimes requires special treatment.
+3. Fill in the `dp` grid data **in order** according to an example.
+ - The "recursive formula" is the core of the "dynamic programming" algorithm. But the "recursive formula" is obscure. If you want to get it, you need to make a table and use data to inspire yourself.
+ - If the original example is not good enough, you need to redesign one yourself.
+ - According to the example, fill in the `dp` grid data "in order", which is very important because it determines the traversal order of the code.
+ - Most of the time, from left to right, from top to bottom. But sometimes it is necessary to traverse from right to left, from bottom to top, from the middle to the right (or left), such as the "palindrome" problems. Sometimes, it is necessary to traverse a line twice, first forward and then backward.
+ - When the order is determined correctly, the starting point is determined. Starting from the starting point, fill in the `dp` grid data "in order". This order is also the order in which the program processes.
+ - In this process, you will get inspiration to write a "recursive formula". If you can already derive the formula, you do not need to complete the grid.
+4. Based on the `dp` grid data, derive the **recursive formula**.
+ - There are three special positions to pay attention to: `dp[i - 1][j - 1]`, `dp[i - 1][j]` and `dp[i][j - 1]`, the current `dp[i][j]` often depends on them.
+ - When operating "two swappable arrays", due to symmetry, we may need to use `dp[i - 1][j]` and `dp[i][j - 1]` at the same time.
+5. Write a program and print the `dp` array. If it is not as expected, adjust it.
+ - Focus on analyzing those values that are not as expected.
+
+After reading the above, do you feel that "dynamic programming" is not that difficult? Try to solve this problem. 🤗
+
+## Pattern of "Subsequence Problems"
+
+- Since there are two swappable arrays (or strings) to compare, we can use **two-dimensional** arrays as `dp`.
+- The traversal order of `dp` array is from top to bottom, then from left to right.
+
+## Step by Step Solutions
+
+1. Determine the **meaning** of each value of the array `dp`.
+ - `dp[i][j]` represents the **minimum** number of operations required to convert `word1`'s first `i` letters to `word2`'s first `j` letters.
+ - `dp[i][j]` is an integer.
+2. Initialize the value of the array `dp`.
+ - Use an example:
+
+ ```
+ After initialization, the 'dp' array would be:
+ # r o s
+ # 0 1 2 3 # dp[0]
+ # h 1 0 0 0
+ # o 2 0 0 0
+ # r 3 0 0 0
+ # s 4 0 0 0
+ # e 5 0 0 0
+ ```
+ - `dp[i][0] = i`, because `dp[i][0]` represents the empty string, and the number of operations is just the number of chars to be deleted.
+ - `dp[0][j] = j`, the reason is the same as the previous line, just viewed from the opposite angle: convert `word2` to `word1`.
+
+3. Fill in the `dp` grid data **in order** according to an example.
+
+ ```
+ 1. Convert `h` to `ros`.
+ # r o s
+ # 0 1 2 3
+ # h 1 1 2 3 # dp[1]
+ ```
+ ```
+ 2. Convert `ho` to `ros`.
+ # r o s
+ # 0 1 2 3
+ # h 1 1 2 3
+ # o 2 2 1 2
+ ```
+ ```
+ 3. Convert `hor` to `ros`.
+ # r o s
+ # 0 1 2 3
+ # h 1 1 2 3
+ # o 2 2 1 2
+ # r 3 2 2 2
+ ```
+ ```
+ 4. Convert `hors` to `ros`.
+ # r o s
+ # 0 1 2 3
+ # h 1 1 2 3
+ # o 2 2 1 2
+ # r 3 2 2 2
+ # s 4 3 3 2
+ ```
+ ```
+ 5. Convert `horse` to `ros`.
+ # r o s
+ # 0 1 2 3
+ # h 1 1 2 3
+ # o 2 2 1 2
+ # r 3 2 2 2
+ # s 4 3 3 2
+ # e 5 4 4 3 # dp[5]
+ ```
+4. Based on the `dp` grid data, derive the **recursive formula**.
+
+ ```python
+ if word1[i - 1] == word2[j - 1]:
+ dp[i][j] = dp[i - 1][j - 1]
+ else:
+ dp[i][j] = min(
+ dp[i - 1][j - 1],
+ dp[i - 1][j],
+ dp[i][j - 1],
+ ) + 1
+ ```
+5. Write a program and print the `dp` array. If it is not as expected, adjust it.
+
+## Complexity
+
+- Time complexity: `O(N * M)`.
+- Space complexity: `O(N * M)`.
## Java
+
```java
class Solution {
public int minDistance(String word1, String word2) {
@@ -158,7 +204,8 @@ class Solution {
```
## C#
-```c#
+
+```csharp
public class Solution
{
public int MinDistance(string word1, string word2)
@@ -192,6 +239,7 @@ public class Solution
```
## Python
+
```python
class Solution:
def minDistance(self, word1: str, word2: str) -> int:
@@ -212,6 +260,7 @@ class Solution:
```
## C++
+
```cpp
class Solution {
public:
@@ -240,6 +289,7 @@ public:
```
## JavaScript
+
```javascript
var minDistance = function (word1, word2) {
const dp = Array(word1.length + 1).fill().map(
@@ -263,6 +313,7 @@ var minDistance = function (word1, word2) {
```
## Go
+
```go
func minDistance(word1 string, word2 string) int {
dp := make([][]int, len(word1) + 1)
@@ -289,6 +340,7 @@ func minDistance(word1 string, word2 string) int {
```
## Ruby
+
```ruby
def min_distance(word1, word2)
dp = Array.new(word1.size + 1) do
@@ -316,12 +368,15 @@ def min_distance(word1, word2)
end
```
-## Rust
-```rust
-// Welcome to create a PR to complete the code of this language, thanks!
-```
-
## Other languages
-```
+
+```java
// Welcome to create a PR to complete the code of this language, thanks!
```
+
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+
+Original link: [72. Edit Distance - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/72-edit-distance).
+
+GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
+
diff --git a/en/1-1000/797-all-paths-from-source-to-target.md b/en/1-1000/797-all-paths-from-source-to-target.md
index 04aa1cf..9ae3115 100644
--- a/en/1-1000/797-all-paths-from-source-to-target.md
+++ b/en/1-1000/797-all-paths-from-source-to-target.md
@@ -1,27 +1,38 @@
-# 797. All Paths From Source to Target
-LeetCode link: [797. All Paths From Source to Target](https://leetcode.com/problems/all-paths-from-source-to-target/)
+# 797. All Paths From Source to Target - LeetCode Python/Java/C++/JS code
+
+Visit original link: [797. All Paths From Source to Target - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/797-all-paths-from-source-to-target) for a better experience!
+
+LeetCode link: [797. All Paths From Source to Target](https://leetcode.com/problems/all-paths-from-source-to-target), difficulty: **Medium**.
+
+## LeetCode description of "797. All Paths From Source to Target"
-## LeetCode problem description
Given a directed acyclic graph (**DAG**) of `n` nodes labeled from `0` to `n - 1`, find all possible paths from node `0` to node `n - 1` and return them in **any order**.
The graph is given as follows: `graph[i]` is a list of all nodes you can visit from node `i` (i.e., there is a directed edge from node `i` to node `graph[i][j]`).
-### Example 1
+### [Example 1]
+

-```
-Input: graph = [[1,2],[3],[3],[]]
-Output: [[0,1,3],[0,2,3]]
-Explanation: There are two paths: 0 -> 1 -> 3 and 0 -> 2 -> 3.
-```
-### Example 2
+**Input**: `graph = [[1,2],[3],[3],[]]`
+
+**Output**: `[[0,1,3],[0,2,3]]`
+
+**Explanation**:
+
+There are two paths: 0 -> 1 -> 3 and 0 -> 2 -> 3.
+
+
+### [Example 2]
+

-```
-Input: graph = [[4,3,1],[3,2,4],[3],[4],[]]
-Output: [[0,4],[0,3,4],[0,1,3,4],[0,1,2,3,4],[0,1,4]]
-```
-### Constraints
+**Input**: `graph = [[4,3,1],[3,2,4],[3],[4],[]]`
+
+**Output**: `[[0,4],[0,3,4],[0,1,3,4],[0,1,2,3,4],[0,1,4]]`
+
+### [Constraints]
+
- `n == graph.length`
- `2 <= n <= 15`
- `0 <= graph[i][j] < n`
@@ -29,293 +40,555 @@ Output: [[0,4],[0,3,4],[0,1,3,4],[0,1,2,3,4],[0,1,4]]
- All the elements of `graph[i]` are **unique**.
- The input graph is **guaranteed** to be a **DAG**.
-# Intuition
-This problem can be solved using **Depth-First Search of a Graph**.
+## Intuition 1
+
+
+
+## Pattern of "Depth-First Search"
+
+**Depth-First Search (DFS)** is a classic graph traversal algorithm characterized by its **"go as deep as possible"** approach when exploring branches of a graph. Starting from the initial vertex, DFS follows a single path as far as possible until it reaches a vertex with no unvisited adjacent nodes, then backtracks to the nearest branching point to continue exploration. This process is implemented using **recursion** or an **explicit stack (iterative method)**, resulting in a **Last-In-First-Out (LIFO)** search order. As a result, DFS can quickly reach deep-level nodes far from the starting point in unweighted graphs.
+
+**Comparison with BFS**:
+
+1. **Search Order**: DFS prioritizes depth-wise exploration, while Breadth-First Search (BFS) expands layer by layer, following a **First-In-First-Out (FIFO)** queue structure.
+2. **Use Cases**: DFS is better suited for strongly connected components or backtracking problems (e.g., finding all paths in a maze), whereas BFS excels at finding the shortest path (in unweighted graphs) or exploring neighboring nodes (e.g., friend recommendations in social networks).
+
+**Unique Aspects of DFS**:
+
+- **Incompleteness**: If the graph is infinitely deep or contains cycles (without visited markers), DFS may fail to terminate, whereas BFS always finds the shortest path (in unweighted graphs).
+- **"One-path deep-dive"** search style makes it more flexible for backtracking, pruning, or path recording, but it may also miss near-optimal solutions.
-# Approach
-1. From node `0`, visit all of its neighbors `graph[node]` in an iteration.
-2. In the iteration, recursively call the `dfs` function to visit all the paths.
-3. Use an array `path` to save the path (node itself inclusive).
-4. Around the `dfs()` call code are the `path.push(node)` (use `node`) and `path.pop()` (undo use `node`).
-5. Use an array `paths` to save the results.
+In summary, DFS reveals the vertical structure of a graph through its depth-first strategy. Its inherent backtracking mechanism, combined with the natural use of a stack, makes it highly effective for path recording and state-space exploration. However, precautions must be taken to handle cycles and the potential absence of optimal solutions.
+
+## Step by Step Solutions
+
+1. Initialize an empty list `paths` to store all valid paths found.
+2. Initialize a stack to manage the DFS traversal. Each element on the stack will store a pair (or tuple) containing the current `node` and the `path` taken to reach that node.
+3. Push the starting state onto the stack: the initial node `0` and an empty path list (e.g., `(0, [])`).
+4. While the stack is not empty:
+ - Pop the top element from the stack, retrieving the current `node` and its associated `path`.
+ - Create a `currentPath` list by appending the current `node` to the `path` popped from the stack. This represents the path leading up to and including the current node.
+ - Check if the current `node` is the target node (`n - 1`, where `n` is the total number of nodes).
+ - If it is the target node, add the `currentPath` to the `paths` list, as a complete path from source to target has been found.
+ - If it is not the target node, iterate through all `neighbor` nodes accessible from the current `node` (i.e., iterate through `graph[node]`).
+ - For each `neighbor`, push a new pair onto the stack: the `neighbor` node and the `currentPath`. This prepares the traversal to explore paths extending from the neighbor.
+5. After the loop finishes (stack is empty), return the `paths` list containing all discovered paths from node `0` to node `n - 1`.
## Complexity
-* Time: `O(2**n)`.
-* Space: `O(n)`.
+
+- Time complexity: `Too complex`.
+- Space complexity: `Too complex`.
## Python
-### Solution 1: New array as 'path' parameter
+
```python
class Solution:
- def __init__(self):
- self.paths = []
- self.graph = None
-
def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:
- self.graph = graph
+ paths = []
+ stack = [(0, [])]
- self.dfs(0, [0])
+ while stack:
+ node, path = stack.pop()
- return self.paths
-
- def dfs(self, node, path):
- if node == len(self.graph) - 1:
- self.paths.append(path.copy())
- return
+ if node == len(graph) - 1:
+ paths.append(path + [node])
+ continue
- for target_node in self.graph[node]:
- self.dfs(target_node, path + [target_node])
+ for target_node in graph[node]:
+ stack.append((target_node, path + [node]))
+
+ return paths
```
-### Solution 2: More efficient by reusing one array (recommended)
+## Java
+
+```java
+class Solution {
+ public List> allPathsSourceTarget(int[][] graph) {
+ List> paths = new ArrayList<>();
+ // Each element in the stack is a pair: (current_node, current_path)
+ Stack>> stack = new Stack<>();
+ List initialPath = new ArrayList<>();
+ stack.push(new Pair<>(0, initialPath));
+
+ int targetNode = graph.length - 1;
+
+ while (!stack.isEmpty()) {
+ var current = stack.pop();
+ int node = current.getKey();
+ var path = current.getValue();
+
+ var nextPath = new ArrayList<>(path);
+ nextPath.add(node);
+
+ if (node == targetNode) {
+ paths.add(nextPath);
+ continue;
+ }
+
+ for (int neighbor : graph[node]) {
+ stack.push(new Pair<>(neighbor, nextPath));
+ }
+ }
+
+ return paths;
+ }
+}
+
+```
+
+## C++
+
+```cpp
+class Solution {
+public:
+ vector> allPathsSourceTarget(vector>& graph) {
+ vector> paths;
+ // Stack stores pairs of (current_node, current_path)
+ stack>> s;
+ s.push({0, {}}); // Start at node 0 with an empty path initially
+
+ int targetNode = graph.size() - 1;
+
+ while (!s.empty()) {
+ auto node_path = s.top();
+ s.pop();
+ int node = node_path.first;
+ vector path = node_path.second;
+
+ // Add the current node to the path
+ path.push_back(node);
+
+ if (node == targetNode) {
+ paths.push_back(path); // Found a path to the target
+ continue;
+ }
+
+ // Explore neighbors
+ for (int neighbor : graph[node]) {
+ s.push({neighbor, path});
+ }
+ }
+
+ return paths;
+ }
+};
+```
+
+## JavaScript
+
+```javascript
+/**
+ * @param {number[][]} graph
+ * @return {number[][]}
+ */
+var allPathsSourceTarget = function(graph) {
+ const paths = [];
+ // Stack stores arrays: [current_node, current_path]
+ const stack = [[0, []]]; // Start at node 0 with an empty path
+ const targetNode = graph.length - 1;
+
+ while (stack.length > 0) {
+ const [node, path] = stack.pop();
+
+ // Create the new path by appending the current node
+ const currentPath = [...path, node];
+
+ if (node === targetNode) {
+ paths.push(currentPath); // Found a path
+ continue;
+ }
+
+ // Explore neighbors
+ for (const neighbor of graph[node]) {
+ stack.push([neighbor, currentPath]); // Push neighbor and the path so far
+ }
+ }
+
+ return paths;
+};
+
+```
+
+## C#
+
+```csharp
+public class Solution {
+ public IList> AllPathsSourceTarget(int[][] graph)
+ {
+ var paths = new List>();
+ // Stack stores tuples: (current_node, current_path)
+ var stack = new Stack<(int node, List path)>();
+ stack.Push((0, new List())); // Start at node 0
+
+ int targetNode = graph.Length - 1;
+
+ while (stack.Count > 0)
+ {
+ var (node, path) = stack.Pop();
+
+ var currentPath = new List(path);
+ currentPath.Add(node);
+
+ if (node == targetNode)
+ {
+ paths.Add(currentPath); // Found a path
+ continue;
+ }
+
+ // Explore neighbors
+ foreach (int neighbor in graph[node])
+ {
+ stack.Push((neighbor, currentPath)); // Push neighbor and the path so far
+ }
+ }
+
+ return paths;
+ }
+}
+```
+
+## Go
+
+```go
+type StackItem struct {
+ Node int
+ Path []int
+}
+
+func allPathsSourceTarget(graph [][]int) [][]int {
+ var paths [][]int
+ stack := []StackItem{{Node: 0, Path: []int{}}} // Start at node 0
+
+ targetNode := len(graph) - 1
+
+ for len(stack) > 0 {
+ currentItem := stack[len(stack) - 1] // Pop from stack
+ stack = stack[:len(stack) - 1]
+
+ node := currentItem.Node
+ path := currentItem.Path
+
+ newPath := append([]int(nil), path...)
+ newPath = append(newPath, node)
+
+ if node == targetNode {
+ paths = append(paths, newPath) // Found a path
+ continue
+ }
+
+ for _, neighbor := range graph[node] {
+ stack = append(stack, StackItem{Node: neighbor, Path: newPath})
+ }
+ }
+
+ return paths
+}
+```
+
+## Ruby
+
+```ruby
+# @param {Integer[][]} graph
+# @return {Integer[][]}
+def all_paths_source_target(graph)
+ paths = []
+ # Stack stores arrays: [current_node, current_path]
+ stack = [[0, []]] # Start at node 0 with an empty path
+ target_node = graph.length - 1
+
+ while !stack.empty?
+ node, path = stack.pop
+
+ # Create the new path by appending the current node
+ current_path = path + [node]
+
+ if node == target_node
+ paths << current_path # Found a path
+ next
+ end
+
+ # Explore neighbors
+ graph[node].each do |neighbor|
+ stack.push([neighbor, current_path])
+ end
+ end
+
+ paths
+end
+```
+
+## Other languages
+
+```java
+// Welcome to create a PR to complete the code of this language, thanks!
+```
+
+## Intuition 2
+
+
+
+## Pattern of "Depth-First Search"
+
+**Depth-First Search (DFS)** is a classic graph traversal algorithm characterized by its **"go as deep as possible"** approach when exploring branches of a graph. Starting from the initial vertex, DFS follows a single path as far as possible until it reaches a vertex with no unvisited adjacent nodes, then backtracks to the nearest branching point to continue exploration. This process is implemented using **recursion** or an **explicit stack (iterative method)**, resulting in a **Last-In-First-Out (LIFO)** search order. As a result, DFS can quickly reach deep-level nodes far from the starting point in unweighted graphs.
+
+**Comparison with BFS**:
+
+1. **Search Order**: DFS prioritizes depth-wise exploration, while Breadth-First Search (BFS) expands layer by layer, following a **First-In-First-Out (FIFO)** queue structure.
+2. **Use Cases**: DFS is better suited for strongly connected components or backtracking problems (e.g., finding all paths in a maze), whereas BFS excels at finding the shortest path (in unweighted graphs) or exploring neighboring nodes (e.g., friend recommendations in social networks).
+
+**Unique Aspects of DFS**:
+
+- **Incompleteness**: If the graph is infinitely deep or contains cycles (without visited markers), DFS may fail to terminate, whereas BFS always finds the shortest path (in unweighted graphs).
+- **"One-path deep-dive"** search style makes it more flexible for backtracking, pruning, or path recording, but it may also miss near-optimal solutions.
+
+In summary, DFS reveals the vertical structure of a graph through its depth-first strategy. Its inherent backtracking mechanism, combined with the natural use of a stack, makes it highly effective for path recording and state-space exploration. However, precautions must be taken to handle cycles and the potential absence of optimal solutions.
+
+## Pattern of "Recursion"
+
+Recursion is an important concept in computer science and mathematics, which refers to the method by which a function calls itself **directly or indirectly** in its definition.
+
+### The core idea of recursion
+
+- **Self-call**: A function calls itself during execution.
+- **Base case**: Equivalent to the termination condition. After reaching the base case, the result can be returned without recursive calls to prevent infinite loops.
+- **Recursive step**: The step by which the problem gradually approaches the "base case".
+
+## Complexity
+
+- Time complexity: `Too complex`.
+- Space complexity: `Too complex`.
+
+## Python
+
```python
class Solution:
- def __init__(self):
- self.paths = []
- self.path = [0]
- self.graph = None
-
def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:
+ self.paths = []
self.graph = graph
+ self.target = len(graph) - 1
- self.dfs(0)
+ self.dfs(0, []) # Start DFS from node 0 with an empty initial path
return self.paths
- def dfs(self, node):
- if node == len(self.graph) - 1:
- self.paths.append(self.path.copy())
- return
-
- for target_node in self.graph[node]:
- self.path.append(target_node)
+ def dfs(self, node, path):
+ current_path = path + [node]
- self.dfs(target_node)
+ if node == self.target: # Base case
+ self.paths.append(current_path)
+ return
- self.path.pop()
+ for neighbor in self.graph[node]: # Recursive step: Explore neighbors
+ self.dfs(neighbor, current_path)
```
## Java
+
```java
class Solution {
- List> paths = new ArrayList<>();
- List path = new ArrayList<>();
- int[][] graph;
+ private List> paths;
+ private int[][] graph;
+ private int targetNode;
public List> allPathsSourceTarget(int[][] graph) {
+ this.paths = new ArrayList<>();
this.graph = graph;
- path.add(0);
+ this.targetNode = graph.length - 1;
- dfs(0);
+ List initialPath = new ArrayList<>();
+ dfs(0, initialPath); // Start DFS from node 0 with an empty initial path
return paths;
}
- void dfs(int node) {
- if (node == graph.length - 1) {
- paths.add(new ArrayList<>(path));
+ private void dfs(int node, List currentPath) {
+ List newPath = new ArrayList<>(currentPath);
+ newPath.add(node);
+
+ if (node == targetNode) { // Base case
+ paths.add(newPath);
return;
}
- for (int targetNode : graph[node]) {
- path.add(targetNode);
-
- dfs(targetNode);
-
- path.removeLast();
+ for (int neighbor : graph[node]) { // Recursive step: Explore neighbors
+ dfs(neighbor, newPath);
}
}
}
```
## C++
+
```cpp
class Solution {
public:
vector> allPathsSourceTarget(vector>& graph) {
- graph_ = graph;
- path_.push_back(0);
+ _graph = graph;
- dfs(0);
+ vector initial_path; // Empty initial path
+ dfs(0, initial_path); // Start DFS from node 0
- return paths_;
+ return _paths;
}
private:
- vector> paths_;
- vector path_;
- vector> graph_;
+ vector> _paths;
+ vector> _graph;
- void dfs(int node) {
- if (node == graph_.size() - 1) {
- paths_.push_back(path_);
+ void dfs(int node, vector current_path) {
+ current_path.push_back(node);
+
+ if (node == _graph.size() - 1) { // Base case
+ _paths.push_back(current_path);
return;
}
- for (int target_node : graph_[node]) {
- path_.push_back(target_node);
-
- dfs(target_node);
-
- path_.pop_back();
+ for (int neighbor : _graph[node]) { // Recursive step: Explore neighbors
+ dfs(neighbor, current_path);
}
}
};
```
## JavaScript
+
```javascript
let paths
-let path
let graph
var allPathsSourceTarget = function (graph_) {
- graph = graph_
paths = []
- path = [0]
+ graph = graph_
- dfs(0)
+ dfs(0, [])
return paths
-};
+}
+
+function dfs(node, currentPath) {
+ const newPath = [...currentPath, node]
-function dfs(node) {
- if (node === graph.length - 1) {
- paths.push([...path])
+ if (node === graph.length - 1) { // Base case
+ paths.push(newPath)
return
}
- for (const targetNode of graph[node]) {
- path.push(targetNode)
-
- dfs(targetNode)
-
- path.pop()
+ for (const neighbor of graph[node]) { // Recursive step: Explore neighbors
+ dfs(neighbor, newPath)
}
}
+
```
## C#
-```c#
+
+```csharp
public class Solution
{
- IList> paths = new List>();
- IList path = new List();
- int[][] graph;
+ private IList> paths;
+ private int[][] graph;
+ private int targetNode;
public IList> AllPathsSourceTarget(int[][] graph)
{
+ this.paths = new List>();
this.graph = graph;
- path.Add(0);
+ this.targetNode = graph.Length - 1;
- dfs(0);
+ Dfs(0, new List());
return paths;
}
- void dfs(int node)
+ private void Dfs(int node, List currentPath)
{
- if (node == graph.Length - 1)
+ var newPath = new List(currentPath);
+ newPath.Add(node);
+
+ if (node == targetNode) // Base case
{
- paths.Add(path.ToList());
+ paths.Add(newPath);
return;
}
- foreach (int targetNode in graph[node])
+ foreach (int neighbor in graph[node]) // Recursive step: Explore neighbors
{
- path.Add(targetNode);
-
- dfs(targetNode);
-
- path.RemoveAt(path.Count - 1);
+ Dfs(neighbor, newPath);
}
}
}
```
## Go
+
```go
var (
paths [][]int
- path []int
graph [][]int
+ targetNode int
)
func allPathsSourceTarget(graph_ [][]int) [][]int {
+ paths = [][]int{}
graph = graph_
- paths = nil
- path = []int{0}
+ targetNode = len(graph) - 1
- dfs(0)
+ dfs(0, []int{})
return paths
}
-func dfs(node int) {
- if (node == len(graph) - 1) {
- paths = append(paths, slices.Clone(path))
+func dfs(node int, currentPath []int) {
+ newPath := append([]int(nil), currentPath...)
+ newPath = append(newPath, node)
+
+ if node == targetNode { // Base case
+ paths = append(paths, newPath)
return
}
- for _, targetNode := range graph[node] {
- path = append(path, targetNode)
-
- dfs(targetNode)
-
- path = path[:len(path) - 1]
+ for _, neighbor := range graph[node] { // Recursive step: Explore neighbors
+ dfs(neighbor, newPath)
}
}
```
## Ruby
+
```ruby
def all_paths_source_target(graph)
- @graph = graph
@paths = []
- @path = [0]
+ @graph = graph
- dfs(0)
+ dfs(0, [])
@paths
end
-def dfs(node)
- if node == @graph.size - 1
- @paths.append(@path.clone)
+def dfs(node, current_path)
+ new_path = current_path + [node]
+
+ if node == @graph.size - 1 # Base case
+ @paths << new_path
return
end
- @graph[node].each do |target_node|
- @path << target_node
-
- dfs(target_node)
-
- @path.pop
+ @graph[node].each do |neighbor| # Recursive step: Explore neighbors
+ dfs(neighbor, new_path)
end
end
```
-## C
-```c
-// Welcome to create a PR to complete the code of this language, thanks!
-```
+## Other languages
-## Kotlin
-```kotlin
+```java
// Welcome to create a PR to complete the code of this language, thanks!
```
-## Swift
-```swift
-// Welcome to create a PR to complete the code of this language, thanks!
-```
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-## Rust
-```rust
-// Welcome to create a PR to complete the code of this language, thanks!
-```
+Original link: [797. All Paths From Source to Target - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/797-all-paths-from-source-to-target).
+
+GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
-## Other languages
-```
-// Welcome to create a PR to complete the code of this language, thanks!
-```
diff --git a/en/1-1000/833-find-and-replace-in-string.md b/en/1-1000/833-find-and-replace-in-string.md
index 99ce716..fdc7f5f 100644
--- a/en/1-1000/833-find-and-replace-in-string.md
+++ b/en/1-1000/833-find-and-replace-in-string.md
@@ -1,6 +1,6 @@
-# 833. Find And Replace in String - LeetCode Best Practices
+# 833. Find And Replace in String - LeetCode Python/Java/C++/JS code
-Visit original link: [833. Find And Replace in String - LeetCode Best Practices](https://leetcoder.net/en/leetcode/833-find-and-replace-in-string) for a better experience!
+Visit original link: [833. Find And Replace in String - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/833-find-and-replace-in-string) for a better experience!
LeetCode link: [833. Find And Replace in String](https://leetcode.com/problems/find-and-replace-in-string), difficulty: **Medium**.
@@ -105,9 +105,9 @@ class Solution:
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [833. Find And Replace in String - LeetCode Best Practices](https://leetcoder.net/en/leetcode/833-find-and-replace-in-string).
+Original link: [833. Find And Replace in String - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/833-find-and-replace-in-string).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1-1000/977-squares-of-a-sorted-array.md b/en/1-1000/977-squares-of-a-sorted-array.md
index 66ec2c6..484ff73 100644
--- a/en/1-1000/977-squares-of-a-sorted-array.md
+++ b/en/1-1000/977-squares-of-a-sorted-array.md
@@ -1,6 +1,6 @@
-# 977. Squares of a Sorted Array - LeetCode Best Practices
+# 977. Squares of a Sorted Array - LeetCode Python/Java/C++/JS code
-Visit original link: [977. Squares of a Sorted Array - LeetCode Best Practices](https://leetcoder.net/en/leetcode/977-squares-of-a-sorted-array) for a better experience!
+Visit original link: [977. Squares of a Sorted Array - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/977-squares-of-a-sorted-array) for a better experience!
LeetCode link: [977. Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array), difficulty: **Easy**.
@@ -346,9 +346,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [977. Squares of a Sorted Array - LeetCode Best Practices](https://leetcoder.net/en/leetcode/977-squares-of-a-sorted-array).
+Original link: [977. Squares of a Sorted Array - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/977-squares-of-a-sorted-array).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/1001-2000/1049-last-stone-weight-ii.md b/en/1001-2000/1049-last-stone-weight-ii.md
index 26f86cd..74fbe4f 100644
--- a/en/1001-2000/1049-last-stone-weight-ii.md
+++ b/en/1001-2000/1049-last-stone-weight-ii.md
@@ -1,6 +1,6 @@
-# 1049. Last Stone Weight II - LeetCode Best Practices
+# 1049. Last Stone Weight II - LeetCode Python/Java/C++/JS code
-Visit original link: [1049. Last Stone Weight II - LeetCode Best Practices](https://leetcoder.net/en/leetcode/1049-last-stone-weight-ii) for a better experience!
+Visit original link: [1049. Last Stone Weight II - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/1049-last-stone-weight-ii) for a better experience!
LeetCode link: [1049. Last Stone Weight II](https://leetcode.com/problems/last-stone-weight-ii), difficulty: **Medium**.
@@ -71,15 +71,15 @@ we can combine 1 and 1 to get 0, so the array converts to [1], then that's t
#### "Dynamic programming" is divided into five steps
-1. Determine the meaning of each value of the array `dp`.
+1. Determine the **meaning** of each value of the array `dp`.
2. Initialize the value of the array `dp`.
-3. Fill in the `dp` grid data "in order" according to an example.
-4. Based on the `dp` grid data, derive the "recursive formula".
+3. Fill in the `dp` grid data **in order** according to an example.
+4. Based on the `dp` grid data, derive the **recursive formula**.
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
#### Detailed description of these five steps
-1. Determine the meaning of each value of the array `dp`.
+1. Determine the **meaning** of each value of the array `dp`.
- First determine whether `dp` is a one-dimensional array or a two-dimensional array. A `one-dimensional rolling array` means that the values of the array are overwritten at each iteration. Most of the time, using `one-dimensional rolling array` instead of `two-dimensional array` can simplify the code; but for some problems, such as operating "two swappable arrays", for the sake of ease of understanding, it is better to use `two-dimensional array`.
- Try to use the meaning of the `return value` required by the problem as the meaning of `dp[i]` (one-dimensional) or `dp[i][j]` (two-dimensional). It works about 60% of the time. If it doesn't work, try other meanings.
- Try to save more information in the design. Repeated information only needs to be saved once in a `dp[i]`.
@@ -87,14 +87,14 @@ we can combine 1 and 1 to get 0, so the array converts to [1], then that's t
2. Initialize the value of the array `dp`. The value of `dp` involves two levels:
1. The length of `dp`. Usually: `condition array length plus 1` or `condition array length`.
2. The value of `dp[i]` or `dp[i][j]`. `dp[0]` or `dp[0][0]` sometimes requires special treatment.
-3. Fill in the `dp` grid data "in order" according to an example.
+3. Fill in the `dp` grid data **in order** according to an example.
- The "recursive formula" is the core of the "dynamic programming" algorithm. But the "recursive formula" is obscure. If you want to get it, you need to make a table and use data to inspire yourself.
- If the original example is not good enough, you need to redesign one yourself.
- According to the example, fill in the `dp` grid data "in order", which is very important because it determines the traversal order of the code.
- Most of the time, from left to right, from top to bottom. But sometimes it is necessary to traverse from right to left, from bottom to top, from the middle to the right (or left), such as the "palindrome" problems. Sometimes, it is necessary to traverse a line twice, first forward and then backward.
- When the order is determined correctly, the starting point is determined. Starting from the starting point, fill in the `dp` grid data "in order". This order is also the order in which the program processes.
- In this process, you will get inspiration to write a "recursive formula". If you can already derive the formula, you do not need to complete the grid.
-4. Based on the `dp` grid data, derive the "recursive formula".
+4. Based on the `dp` grid data, derive the **recursive formula**.
- There are three special positions to pay attention to: `dp[i - 1][j - 1]`, `dp[i - 1][j]` and `dp[i][j - 1]`, the current `dp[i][j]` often depends on them.
- When operating "two swappable arrays", due to symmetry, we may need to use `dp[i - 1][j]` and `dp[i][j - 1]` at the same time.
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
@@ -137,7 +137,7 @@ Because "0/1 Knapsack Problem" belongs to "Dynamic Programming", I will explain
```
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
-## Steps
+## Step by Step Solutions
1. Determine the **meaning** of the `dp[j]`
- `dp[j]` represents whether it is possible to `sum` the first `i` `stones` to get `j`.
@@ -593,9 +593,9 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [1049. Last Stone Weight II - LeetCode Best Practices](https://leetcoder.net/en/leetcode/1049-last-stone-weight-ii).
+Original link: [1049. Last Stone Weight II - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/1049-last-stone-weight-ii).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/3001-4000/3478-choose-k-elements-with-maximum-sum.md b/en/3001-4000/3478-choose-k-elements-with-maximum-sum.md
index cebd7f7..5691cd7 100644
--- a/en/3001-4000/3478-choose-k-elements-with-maximum-sum.md
+++ b/en/3001-4000/3478-choose-k-elements-with-maximum-sum.md
@@ -1,6 +1,6 @@
-# 3478. Choose K Elements With Maximum Sum - LeetCode Best Practices
+# 3478. Choose K Elements With Maximum Sum - LeetCode Python/Java/C++/JS code
-Visit original link: [3478. Choose K Elements With Maximum Sum - LeetCode Best Practices](https://leetcoder.net/en/leetcode/3478-choose-k-elements-with-maximum-sum) for a better experience!
+Visit original link: [3478. Choose K Elements With Maximum Sum - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/3478-choose-k-elements-with-maximum-sum) for a better experience!
LeetCode link: [3478. Choose K Elements With Maximum Sum](https://leetcode.com/problems/choose-k-elements-with-maximum-sum), difficulty: **Medium**.
@@ -129,9 +129,9 @@ class Solution:
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [3478. Choose K Elements With Maximum Sum - LeetCode Best Practices](https://leetcoder.net/en/leetcode/3478-choose-k-elements-with-maximum-sum).
+Original link: [3478. Choose K Elements With Maximum Sum - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/3478-choose-k-elements-with-maximum-sum).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/en/3001-4000/3494-find-the-minimum-amount-of-time-to-brew-potions.md b/en/3001-4000/3494-find-the-minimum-amount-of-time-to-brew-potions.md
index 0b7dfea..4862448 100644
--- a/en/3001-4000/3494-find-the-minimum-amount-of-time-to-brew-potions.md
+++ b/en/3001-4000/3494-find-the-minimum-amount-of-time-to-brew-potions.md
@@ -1,6 +1,6 @@
-# 3494. Find the Minimum Amount of Time to Brew Potions - LeetCode Best Practices
+# 3494. Find the Minimum Amount of Time to Brew Potions - LeetCode Python/Java/C++/JS code
-Visit original link: [3494. Find the Minimum Amount of Time to Brew Potions - LeetCode Best Practices](https://leetcoder.net/en/leetcode/3494-find-the-minimum-amount-of-time-to-brew-potions) for a better experience!
+Visit original link: [3494. Find the Minimum Amount of Time to Brew Potions - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/3494-find-the-minimum-amount-of-time-to-brew-potions) for a better experience!
LeetCode link: [3494. Find the Minimum Amount of Time to Brew Potions](https://leetcode.com/problems/find-the-minimum-amount-of-time-to-brew-potions), difficulty: **Medium**.
@@ -131,15 +131,15 @@ Return the **minimum** amount of time required for the potions to be brewed prop
#### "Dynamic programming" is divided into five steps
-1. Determine the meaning of each value of the array `dp`.
+1. Determine the **meaning** of each value of the array `dp`.
2. Initialize the value of the array `dp`.
-3. Fill in the `dp` grid data "in order" according to an example.
-4. Based on the `dp` grid data, derive the "recursive formula".
+3. Fill in the `dp` grid data **in order** according to an example.
+4. Based on the `dp` grid data, derive the **recursive formula**.
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
#### Detailed description of these five steps
-1. Determine the meaning of each value of the array `dp`.
+1. Determine the **meaning** of each value of the array `dp`.
- First determine whether `dp` is a one-dimensional array or a two-dimensional array. A `one-dimensional rolling array` means that the values of the array are overwritten at each iteration. Most of the time, using `one-dimensional rolling array` instead of `two-dimensional array` can simplify the code; but for some problems, such as operating "two swappable arrays", for the sake of ease of understanding, it is better to use `two-dimensional array`.
- Try to use the meaning of the `return value` required by the problem as the meaning of `dp[i]` (one-dimensional) or `dp[i][j]` (two-dimensional). It works about 60% of the time. If it doesn't work, try other meanings.
- Try to save more information in the design. Repeated information only needs to be saved once in a `dp[i]`.
@@ -147,14 +147,14 @@ Return the **minimum** amount of time required for the potions to be brewed prop
2. Initialize the value of the array `dp`. The value of `dp` involves two levels:
1. The length of `dp`. Usually: `condition array length plus 1` or `condition array length`.
2. The value of `dp[i]` or `dp[i][j]`. `dp[0]` or `dp[0][0]` sometimes requires special treatment.
-3. Fill in the `dp` grid data "in order" according to an example.
+3. Fill in the `dp` grid data **in order** according to an example.
- The "recursive formula" is the core of the "dynamic programming" algorithm. But the "recursive formula" is obscure. If you want to get it, you need to make a table and use data to inspire yourself.
- If the original example is not good enough, you need to redesign one yourself.
- According to the example, fill in the `dp` grid data "in order", which is very important because it determines the traversal order of the code.
- Most of the time, from left to right, from top to bottom. But sometimes it is necessary to traverse from right to left, from bottom to top, from the middle to the right (or left), such as the "palindrome" problems. Sometimes, it is necessary to traverse a line twice, first forward and then backward.
- When the order is determined correctly, the starting point is determined. Starting from the starting point, fill in the `dp` grid data "in order". This order is also the order in which the program processes.
- In this process, you will get inspiration to write a "recursive formula". If you can already derive the formula, you do not need to complete the grid.
-4. Based on the `dp` grid data, derive the "recursive formula".
+4. Based on the `dp` grid data, derive the **recursive formula**.
- There are three special positions to pay attention to: `dp[i - 1][j - 1]`, `dp[i - 1][j]` and `dp[i][j - 1]`, the current `dp[i][j]` often depends on them.
- When operating "two swappable arrays", due to symmetry, we may need to use `dp[i - 1][j]` and `dp[i][j - 1]` at the same time.
5. Write a program and print the `dp` array. If it is not as expected, adjust it.
@@ -162,7 +162,7 @@ Return the **minimum** amount of time required for the potions to be brewed prop
After reading the above, do you feel that "dynamic programming" is not that difficult? Try to solve this problem. 🤗
-## Steps
+## Step by Step Solutions
1. Determine the meaning of each value of the array `dp`. So what does each `dp[i][j]` represent?
mark-detail The row represents the potion, and the column represents the wizard, which has been hinted in the question.
The meaning is: the time it takes for the `j`th wizard to complete the `i`th bottle of potion. I deliberately did not add the word "shortest" because the potion cannot be separated from the hands of the wizard during the manufacturing process! mark-detail
@@ -432,9 +432,9 @@ func minTime(skill []int, mana []int) int64 {
// Welcome to create a PR to complete the code of this language, thanks!
```
-Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
+Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
-Original link: [3494. Find the Minimum Amount of Time to Brew Potions - LeetCode Best Practices](https://leetcoder.net/en/leetcode/3494-find-the-minimum-amount-of-time-to-brew-potions).
+Original link: [3494. Find the Minimum Amount of Time to Brew Potions - LeetCode Python/Java/C++/JS code](https://leetcodepython.com/en/leetcode/3494-find-the-minimum-amount-of-time-to-brew-potions).
GitHub repository: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/1-two-sum.md b/zh/1-1000/1-two-sum.md
index 60095d1..d24b4a7 100644
--- a/zh/1-1000/1-two-sum.md
+++ b/zh/1-1000/1-two-sum.md
@@ -1,10 +1,10 @@
-# 1. 两数之和 - 力扣题解最佳实践
+# 1. 两数之和 - LeetCode Python/Java/C++ 题解
-访问原文链接:[1. 两数之和 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/1-two-sum),体验更佳!
+访问原文链接:[1. 两数之和 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/1-two-sum),体验更佳!
-力扣链接:[1. 两数之和](https://leetcode.cn/problems/two-sum), 难度:**简单**。
+力扣链接:[1. 两数之和](https://leetcode.cn/problems/two-sum), 难度等级:**简单**。
-## 力扣“1. 两数之和”问题描述
+## LeetCode “1. 两数之和”问题描述
给定一个整数数组 `nums` 和一个整数目标值 `target`,请你在该数组中找出 **和为目标值** `target` 的那 **两个** 整数,并返回它们的数组下标。
@@ -321,10 +321,10 @@ class Solution:
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[1. 两数之和 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/1-two-sum).
+原文链接:[1. 两数之和 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/1-two-sum).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/15-3sum.md b/zh/1-1000/15-3sum.md
index be038e4..1af3956 100644
--- a/zh/1-1000/15-3sum.md
+++ b/zh/1-1000/15-3sum.md
@@ -1,10 +1,10 @@
-# 15. 三数之和 - 力扣题解最佳实践
+# 15. 三数之和 - LeetCode Python/Java/C++ 题解
-访问原文链接:[15. 三数之和 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/15-3sum),体验更佳!
+访问原文链接:[15. 三数之和 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/15-3sum),体验更佳!
-力扣链接:[15. 三数之和](https://leetcode.cn/problems/3sum), 难度:**中等**。
+力扣链接:[15. 三数之和](https://leetcode.cn/problems/3sum), 难度等级:**中等**。
-## 力扣“15. 三数之和”问题描述
+## LeetCode “15. 三数之和”问题描述
给你一个整数数组 `nums` ,判断是否存在三元组 `[nums[i], nums[j], nums[k]]` 满足 `i != j`、`i != k` 且 `j != k` ,同时还满足 `nums[i] + nums[j] + nums[k] == 0` 。请你返回所有和为 `0` 且不重复的三元组。
@@ -505,10 +505,10 @@ def duplicate_removed_nums(nums):
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[15. 三数之和 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/15-3sum).
+原文链接:[15. 三数之和 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/15-3sum).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/160-intersection-of-two-linked-lists.md b/zh/1-1000/160-intersection-of-two-linked-lists.md
index 9d28a1b..f4afcfd 100644
--- a/zh/1-1000/160-intersection-of-two-linked-lists.md
+++ b/zh/1-1000/160-intersection-of-two-linked-lists.md
@@ -1,10 +1,10 @@
-# 160. 相交链表 - 力扣题解最佳实践
+# 160. 相交链表 - LeetCode Python/Java/C++ 题解
-访问原文链接:[160. 相交链表 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/160-intersection-of-two-linked-lists),体验更佳!
+访问原文链接:[160. 相交链表 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/160-intersection-of-two-linked-lists),体验更佳!
-力扣链接:[160. 相交链表](https://leetcode.cn/problems/intersection-of-two-linked-lists), 难度:**简单**。
+力扣链接:[160. 相交链表](https://leetcode.cn/problems/intersection-of-two-linked-lists), 难度等级:**简单**。
-## 力扣“160. 相交链表”问题描述
+## LeetCode “160. 相交链表”问题描述
给你两个单链表的头节点 `headA` 和 `headB` ,请你找出并返回两个单链表相交的起始节点。如果两个链表不存在相交节点,返回 `null` 。
@@ -492,10 +492,10 @@ func getIntersectionNode(headA, headB *ListNode) *ListNode {
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[160. 相交链表 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/160-intersection-of-two-linked-lists).
+原文链接:[160. 相交链表 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/160-intersection-of-two-linked-lists).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/18-4sum.md b/zh/1-1000/18-4sum.md
index 3fd6793..1218c37 100644
--- a/zh/1-1000/18-4sum.md
+++ b/zh/1-1000/18-4sum.md
@@ -1,10 +1,10 @@
-# 18. 四数之和 - 力扣题解最佳实践
+# 18. 四数之和 - LeetCode Python/Java/C++ 题解
-访问原文链接:[18. 四数之和 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/18-4sum),体验更佳!
+访问原文链接:[18. 四数之和 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/18-4sum),体验更佳!
-力扣链接:[18. 四数之和](https://leetcode.cn/problems/4sum), 难度:**中等**。
+力扣链接:[18. 四数之和](https://leetcode.cn/problems/4sum), 难度等级:**中等**。
-## 力扣“18. 四数之和”问题描述
+## LeetCode “18. 四数之和”问题描述
给你一个由 `n` 个整数组成的数组 `nums` ,和一个目标值 `target` 。请你找出并返回满足下述全部条件且**不重复**的四元组 `[nums[a], nums[b], nums[c], nums[d]]` (若两个四元组元素一一对应,则认为两个四元组重复):
@@ -371,10 +371,10 @@ public class Solution {
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[18. 四数之和 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/18-4sum).
+原文链接:[18. 四数之和 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/18-4sum).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/19-remove-nth-node-from-end-of-list.md b/zh/1-1000/19-remove-nth-node-from-end-of-list.md
index 01e0701..b07235e 100644
--- a/zh/1-1000/19-remove-nth-node-from-end-of-list.md
+++ b/zh/1-1000/19-remove-nth-node-from-end-of-list.md
@@ -1,10 +1,10 @@
-# 19. 删除链表的倒数第 N 个结点 - 力扣题解最佳实践
+# 19. 删除链表的倒数第 N 个结点 - LeetCode Python/Java/C++ 题解
-访问原文链接:[19. 删除链表的倒数第 N 个结点 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/19-remove-nth-node-from-end-of-list),体验更佳!
+访问原文链接:[19. 删除链表的倒数第 N 个结点 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/19-remove-nth-node-from-end-of-list),体验更佳!
-力扣链接:[19. 删除链表的倒数第 N 个结点](https://leetcode.cn/problems/remove-nth-node-from-end-of-list), 难度:**中等**。
+力扣链接:[19. 删除链表的倒数第 N 个结点](https://leetcode.cn/problems/remove-nth-node-from-end-of-list), 难度等级:**中等**。
-## 力扣“19. 删除链表的倒数第 N 个结点”问题描述
+## LeetCode “19. 删除链表的倒数第 N 个结点”问题描述
给你一个链表,删除链表的倒数第 `n` 个结点,并且返回链表的头结点。
@@ -382,10 +382,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[19. 删除链表的倒数第 N 个结点 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/19-remove-nth-node-from-end-of-list).
+原文链接:[19. 删除链表的倒数第 N 个结点 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/19-remove-nth-node-from-end-of-list).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/20-valid-parentheses.md b/zh/1-1000/20-valid-parentheses.md
index 9648082..5db02f2 100644
--- a/zh/1-1000/20-valid-parentheses.md
+++ b/zh/1-1000/20-valid-parentheses.md
@@ -1,10 +1,10 @@
-# 20. 有效的括号 - 力扣题解最佳实践
+# 20. 有效的括号 - LeetCode Python/Java/C++ 题解
-访问原文链接:[20. 有效的括号 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/20-valid-parentheses),体验更佳!
+访问原文链接:[20. 有效的括号 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/20-valid-parentheses),体验更佳!
-力扣链接:[20. 有效的括号](https://leetcode.cn/problems/valid-parentheses), 难度:**简单**。
+力扣链接:[20. 有效的括号](https://leetcode.cn/problems/valid-parentheses), 难度等级:**简单**。
-## 力扣“20. 有效的括号”问题描述
+## LeetCode “20. 有效的括号”问题描述
给定一个只包括 `(`,`)`,`{`,`}`,`[`,`]` 的字符串 `s` ,判断字符串是否有效。
@@ -348,10 +348,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[20. 有效的括号 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/20-valid-parentheses).
+原文链接:[20. 有效的括号 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/20-valid-parentheses).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/202-happy-number.md b/zh/1-1000/202-happy-number.md
index 09a5bda..d87edc5 100644
--- a/zh/1-1000/202-happy-number.md
+++ b/zh/1-1000/202-happy-number.md
@@ -1,10 +1,10 @@
-# 202. 快乐数 - 力扣题解最佳实践
+# 202. 快乐数 - LeetCode Python/Java/C++ 题解
-访问原文链接:[202. 快乐数 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/202-happy-number),体验更佳!
+访问原文链接:[202. 快乐数 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/202-happy-number),体验更佳!
-力扣链接:[202. 快乐数](https://leetcode.cn/problems/happy-number), 难度:**简单**。
+力扣链接:[202. 快乐数](https://leetcode.cn/problems/happy-number), 难度等级:**简单**。
-## 力扣“202. 快乐数”问题描述
+## LeetCode “202. 快乐数”问题描述
编写一个算法来判断一个数 `n` 是不是快乐数。
@@ -271,10 +271,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[202. 快乐数 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/202-happy-number).
+原文链接:[202. 快乐数 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/202-happy-number).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/203-remove-linked-list-elements.md b/zh/1-1000/203-remove-linked-list-elements.md
index 4c39a78..36260d0 100644
--- a/zh/1-1000/203-remove-linked-list-elements.md
+++ b/zh/1-1000/203-remove-linked-list-elements.md
@@ -1,10 +1,10 @@
-# 203. 移除链表元素 - 力扣题解最佳实践
+# 203. 移除链表元素 - LeetCode Python/Java/C++ 题解
-访问原文链接:[203. 移除链表元素 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/203-remove-linked-list-elements),体验更佳!
+访问原文链接:[203. 移除链表元素 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/203-remove-linked-list-elements),体验更佳!
-力扣链接:[203. 移除链表元素](https://leetcode.cn/problems/remove-linked-list-elements), 难度:**简单**。
+力扣链接:[203. 移除链表元素](https://leetcode.cn/problems/remove-linked-list-elements), 难度等级:**简单**。
-## 力扣“203. 移除链表元素”问题描述
+## LeetCode “203. 移除链表元素”问题描述
给你一个链表的头节点 `head` 和一个整数 `val` ,请你删除链表中所有满足 `Node.val == val` 的节点,并返回 **新的头节点** 。
@@ -264,10 +264,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[203. 移除链表元素 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/203-remove-linked-list-elements).
+原文链接:[203. 移除链表元素 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/203-remove-linked-list-elements).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/206-reverse-linked-list.md b/zh/1-1000/206-reverse-linked-list.md
index f9402f4..6b93aa9 100644
--- a/zh/1-1000/206-reverse-linked-list.md
+++ b/zh/1-1000/206-reverse-linked-list.md
@@ -1,10 +1,10 @@
-# 206. 反转链表 - 力扣题解最佳实践
+# 206. 反转链表 - LeetCode Python/Java/C++ 题解
-访问原文链接:[206. 反转链表 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/206-reverse-linked-list),体验更佳!
+访问原文链接:[206. 反转链表 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/206-reverse-linked-list),体验更佳!
-力扣链接:[206. 反转链表](https://leetcode.cn/problems/reverse-linked-list), 难度:**简单**。
+力扣链接:[206. 反转链表](https://leetcode.cn/problems/reverse-linked-list), 难度等级:**简单**。
-## 力扣“206. 反转链表”问题描述
+## LeetCode “206. 反转链表”问题描述
给你单链表的头节点 `head` ,请你反转链表,并返回反转后的链表。
@@ -286,10 +286,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[206. 反转链表 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/206-reverse-linked-list).
+原文链接:[206. 反转链表 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/206-reverse-linked-list).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/209-minimum-size-subarray-sum.md b/zh/1-1000/209-minimum-size-subarray-sum.md
index 8b846f9..7c99167 100644
--- a/zh/1-1000/209-minimum-size-subarray-sum.md
+++ b/zh/1-1000/209-minimum-size-subarray-sum.md
@@ -1,10 +1,10 @@
-# 209. 长度最小的子数组 - 力扣题解最佳实践
+# 209. 长度最小的子数组 - LeetCode Python/Java/C++ 题解
-访问原文链接:[209. 长度最小的子数组 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/209-minimum-size-subarray-sum),体验更佳!
+访问原文链接:[209. 长度最小的子数组 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/209-minimum-size-subarray-sum),体验更佳!
-力扣链接:[209. 长度最小的子数组](https://leetcode.cn/problems/minimum-size-subarray-sum), 难度:**中等**。
+力扣链接:[209. 长度最小的子数组](https://leetcode.cn/problems/minimum-size-subarray-sum), 难度等级:**中等**。
-## 力扣“209. 长度最小的子数组”问题描述
+## LeetCode “209. 长度最小的子数组”问题描述
给定一个含有 `n` 个正整数的数组和一个正整数 `target` 。
@@ -292,10 +292,10 @@ public:
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[209. 长度最小的子数组 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/209-minimum-size-subarray-sum).
+原文链接:[209. 长度最小的子数组 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/209-minimum-size-subarray-sum).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/225-implement-stack-using-queues.md b/zh/1-1000/225-implement-stack-using-queues.md
index 953c6df..a54fa54 100644
--- a/zh/1-1000/225-implement-stack-using-queues.md
+++ b/zh/1-1000/225-implement-stack-using-queues.md
@@ -1,10 +1,10 @@
-# 225. 用队列实现栈 - 力扣题解最佳实践
+# 225. 用队列实现栈 - LeetCode Python/Java/C++ 题解
-访问原文链接:[225. 用队列实现栈 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/225-implement-stack-using-queues),体验更佳!
+访问原文链接:[225. 用队列实现栈 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/225-implement-stack-using-queues),体验更佳!
-力扣链接:[225. 用队列实现栈](https://leetcode.cn/problems/implement-stack-using-queues), 难度:**简单**。
+力扣链接:[225. 用队列实现栈](https://leetcode.cn/problems/implement-stack-using-queues), 难度等级:**简单**。
-## 力扣“225. 用队列实现栈”问题描述
+## LeetCode “225. 用队列实现栈”问题描述
请你仅使用两个队列实现一个后入先出(LIFO)的栈,并支持普通栈的全部四种操作(`push`、`top`、`pop` 和 `empty`)。
@@ -702,10 +702,10 @@ public class MyStack
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[225. 用队列实现栈 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/225-implement-stack-using-queues).
+原文链接:[225. 用队列实现栈 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/225-implement-stack-using-queues).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/232-implement-queue-using-stacks.md b/zh/1-1000/232-implement-queue-using-stacks.md
index e9c172b..2d411ab 100644
--- a/zh/1-1000/232-implement-queue-using-stacks.md
+++ b/zh/1-1000/232-implement-queue-using-stacks.md
@@ -1,10 +1,10 @@
-# 232. 用栈实现队列 - 力扣题解最佳实践
+# 232. 用栈实现队列 - LeetCode Python/Java/C++ 题解
-访问原文链接:[232. 用栈实现队列 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/232-implement-queue-using-stacks),体验更佳!
+访问原文链接:[232. 用栈实现队列 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/232-implement-queue-using-stacks),体验更佳!
-力扣链接:[232. 用栈实现队列](https://leetcode.cn/problems/implement-queue-using-stacks), 难度:**简单**。
+力扣链接:[232. 用栈实现队列](https://leetcode.cn/problems/implement-queue-using-stacks), 难度等级:**简单**。
-## 力扣“232. 用栈实现队列”问题描述
+## LeetCode “232. 用栈实现队列”问题描述
请你仅使用两个栈实现先入先出队列。队列应当支持一般队列支持的所有操作(`push`、`pop`、`peek`、`empty`):
@@ -348,10 +348,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[232. 用栈实现队列 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/232-implement-queue-using-stacks).
+原文链接:[232. 用栈实现队列 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/232-implement-queue-using-stacks).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/24-swap-nodes-in-pairs.md b/zh/1-1000/24-swap-nodes-in-pairs.md
index 15cc555..4e3701e 100644
--- a/zh/1-1000/24-swap-nodes-in-pairs.md
+++ b/zh/1-1000/24-swap-nodes-in-pairs.md
@@ -1,10 +1,10 @@
-# 24. 两两交换链表中的节点 - 力扣题解最佳实践
+# 24. 两两交换链表中的节点 - LeetCode Python/Java/C++ 题解
-访问原文链接:[24. 两两交换链表中的节点 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/24-swap-nodes-in-pairs),体验更佳!
+访问原文链接:[24. 两两交换链表中的节点 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/24-swap-nodes-in-pairs),体验更佳!
-力扣链接:[24. 两两交换链表中的节点](https://leetcode.cn/problems/swap-nodes-in-pairs), 难度:**中等**。
+力扣链接:[24. 两两交换链表中的节点](https://leetcode.cn/problems/swap-nodes-in-pairs), 难度等级:**中等**。
-## 力扣“24. 两两交换链表中的节点”问题描述
+## LeetCode “24. 两两交换链表中的节点”问题描述
给你一个链表,两两交换其中相邻的节点,并返回交换后链表的头节点。你必须在不修改节点内部的值的情况下完成本题(即,只能进行节点交换)。
@@ -370,10 +370,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[24. 两两交换链表中的节点 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/24-swap-nodes-in-pairs).
+原文链接:[24. 两两交换链表中的节点 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/24-swap-nodes-in-pairs).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/242-valid-anagram.md b/zh/1-1000/242-valid-anagram.md
index 4b3b329..949da3c 100644
--- a/zh/1-1000/242-valid-anagram.md
+++ b/zh/1-1000/242-valid-anagram.md
@@ -1,10 +1,10 @@
-# 242. 有效的字母异位词 - 力扣题解最佳实践
+# 242. 有效的字母异位词 - LeetCode Python/Java/C++ 题解
-访问原文链接:[242. 有效的字母异位词 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/242-valid-anagram),体验更佳!
+访问原文链接:[242. 有效的字母异位词 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/242-valid-anagram),体验更佳!
-力扣链接:[242. 有效的字母异位词](https://leetcode.cn/problems/valid-anagram), 难度:**简单**。
+力扣链接:[242. 有效的字母异位词](https://leetcode.cn/problems/valid-anagram), 难度等级:**简单**。
-## 力扣“242. 有效的字母异位词”问题描述
+## LeetCode “242. 有效的字母异位词”问题描述
给定两个字符串 `s` 和 `t` ,编写一个函数来判断 `t` 是否是 `s` 的 **字母异位词**。
@@ -215,10 +215,10 @@ public:
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[242. 有效的字母异位词 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/242-valid-anagram).
+原文链接:[242. 有效的字母异位词 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/242-valid-anagram).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/27-remove-element.md b/zh/1-1000/27-remove-element.md
index fe9a4f8..03c4b86 100644
--- a/zh/1-1000/27-remove-element.md
+++ b/zh/1-1000/27-remove-element.md
@@ -1,10 +1,10 @@
-# 27. 移除元素 - 力扣题解最佳实践
+# 27. 移除元素 - LeetCode Python/Java/C++ 题解
-访问原文链接:[27. 移除元素 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/27-remove-element),体验更佳!
+访问原文链接:[27. 移除元素 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/27-remove-element),体验更佳!
-力扣链接:[27. 移除元素](https://leetcode.cn/problems/remove-element), 难度:**简单**。
+力扣链接:[27. 移除元素](https://leetcode.cn/problems/remove-element), 难度等级:**简单**。
-## 力扣“27. 移除元素”问题描述
+## LeetCode “27. 移除元素”问题描述
给你一个数组 `nums` 和一个值 `val`,你需要 [原地](https://en.wikipedia.org/wiki/In-place_algorithm) 移除所有数值等于 `val` 的元素。元素的顺序可能发生改变。然后返回 `nums` 中与 `val` 不同的元素的数量。
@@ -428,10 +428,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[27. 移除元素 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/27-remove-element).
+原文链接:[27. 移除元素 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/27-remove-element).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/28-find-the-index-of-the-first-occurrence-in-a-string.md b/zh/1-1000/28-find-the-index-of-the-first-occurrence-in-a-string.md
index ab0537c..8487abd 100644
--- a/zh/1-1000/28-find-the-index-of-the-first-occurrence-in-a-string.md
+++ b/zh/1-1000/28-find-the-index-of-the-first-occurrence-in-a-string.md
@@ -1,10 +1,10 @@
-# 28. 找出字符串中第一个匹配项的下标 - 力扣题解最佳实践
+# 28. 找出字符串中第一个匹配项的下标 - LeetCode Python/Java/C++ 题解
-访问原文链接:[28. 找出字符串中第一个匹配项的下标 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/28-find-the-index-of-the-first-occurrence-in-a-string),体验更佳!
+访问原文链接:[28. 找出字符串中第一个匹配项的下标 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/28-find-the-index-of-the-first-occurrence-in-a-string),体验更佳!
-力扣链接:[28. 找出字符串中第一个匹配项的下标](https://leetcode.cn/problems/find-the-index-of-the-first-occurrence-in-a-string), 难度:**简单**。
+力扣链接:[28. 找出字符串中第一个匹配项的下标](https://leetcode.cn/problems/find-the-index-of-the-first-occurrence-in-a-string), 难度等级:**简单**。
-## 力扣“28. 找出字符串中第一个匹配项的下标”问题描述
+## LeetCode “28. 找出字符串中第一个匹配项的下标”问题描述
给你两个字符串 `haystack` 和 `needle` ,请你在 `haystack` 字符串中找出 `needle` 字符串的第一个匹配项的下标(下标从 `0` 开始)。如果 `needle` 不是 `haystack` 的一部分,则返回 `-1` 。
@@ -195,10 +195,10 @@ public class Solution {
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[28. 找出字符串中第一个匹配项的下标 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/28-find-the-index-of-the-first-occurrence-in-a-string).
+原文链接:[28. 找出字符串中第一个匹配项的下标 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/28-find-the-index-of-the-first-occurrence-in-a-string).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/303-range-sum-query-immutable.md b/zh/1-1000/303-range-sum-query-immutable.md
index 5a6c36c..b119d62 100644
--- a/zh/1-1000/303-range-sum-query-immutable.md
+++ b/zh/1-1000/303-range-sum-query-immutable.md
@@ -1,10 +1,10 @@
-# 303. 区域和检索 - 数组不可变 - 力扣题解最佳实践
+# 303. 区域和检索 - 数组不可变 - LeetCode Python/Java/C++ 题解
-访问原文链接:[303. 区域和检索 - 数组不可变 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/303-range-sum-query-immutable),体验更佳!
+访问原文链接:[303. 区域和检索 - 数组不可变 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/303-range-sum-query-immutable),体验更佳!
-力扣链接:[303. 区域和检索 - 数组不可变](https://leetcode.cn/problems/range-sum-query-immutable), 难度:**简单**。
+力扣链接:[303. 区域和检索 - 数组不可变](https://leetcode.cn/problems/range-sum-query-immutable), 难度等级:**简单**。
-## 力扣“303. 区域和检索 - 数组不可变”问题描述
+## LeetCode “303. 区域和检索 - 数组不可变”问题描述
给定一个整数数组 `nums`,处理以下类型的多个查询:
@@ -231,10 +231,10 @@ class NumArray:
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[303. 区域和检索 - 数组不可变 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/303-range-sum-query-immutable).
+原文链接:[303. 区域和检索 - 数组不可变 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/303-range-sum-query-immutable).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/344-reverse-string.md b/zh/1-1000/344-reverse-string.md
index 1c8cfc9..5c95719 100644
--- a/zh/1-1000/344-reverse-string.md
+++ b/zh/1-1000/344-reverse-string.md
@@ -1,10 +1,10 @@
-# 344. 反转字符串 - 力扣题解最佳实践
+# 344. 反转字符串 - LeetCode Python/Java/C++ 题解
-访问原文链接:[344. 反转字符串 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/344-reverse-string),体验更佳!
+访问原文链接:[344. 反转字符串 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/344-reverse-string),体验更佳!
-力扣链接:[344. 反转字符串](https://leetcode.cn/problems/reverse-string), 难度:**简单**。
+力扣链接:[344. 反转字符串](https://leetcode.cn/problems/reverse-string), 难度等级:**简单**。
-## 力扣“344. 反转字符串”问题描述
+## LeetCode “344. 反转字符串”问题描述
编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组 `s` 的形式给出。
@@ -212,10 +212,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[344. 反转字符串 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/344-reverse-string).
+原文链接:[344. 反转字符串 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/344-reverse-string).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/349-intersection-of-two-arrays.md b/zh/1-1000/349-intersection-of-two-arrays.md
index 96ebb4c..4d15c5e 100644
--- a/zh/1-1000/349-intersection-of-two-arrays.md
+++ b/zh/1-1000/349-intersection-of-two-arrays.md
@@ -1,10 +1,10 @@
-# 349. 两个数组的交集 - 力扣题解最佳实践
+# 349. 两个数组的交集 - LeetCode Python/Java/C++ 题解
-访问原文链接:[349. 两个数组的交集 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/349-intersection-of-two-arrays),体验更佳!
+访问原文链接:[349. 两个数组的交集 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/349-intersection-of-two-arrays),体验更佳!
-力扣链接:[349. 两个数组的交集](https://leetcode.cn/problems/intersection-of-two-arrays), 难度:**简单**。
+力扣链接:[349. 两个数组的交集](https://leetcode.cn/problems/intersection-of-two-arrays), 难度等级:**简单**。
-## 力扣“349. 两个数组的交集”问题描述
+## LeetCode “349. 两个数组的交集”问题描述
给定两个数组 `nums1` 和 `nums2` ,返回 _它们的 **交集**_ 。输出结果中的每个元素一定是 **唯一** 的。我们可以 **不考虑输出结果的顺序**。
@@ -185,10 +185,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[349. 两个数组的交集 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/349-intersection-of-two-arrays).
+原文链接:[349. 两个数组的交集 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/349-intersection-of-two-arrays).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/383-ransom-note.md b/zh/1-1000/383-ransom-note.md
index 22e8ad4..6083eac 100644
--- a/zh/1-1000/383-ransom-note.md
+++ b/zh/1-1000/383-ransom-note.md
@@ -1,10 +1,10 @@
-# 383. 赎金信 - 力扣题解最佳实践
+# 383. 赎金信 - LeetCode Python/Java/C++ 题解
-访问原文链接:[383. 赎金信 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/383-ransom-note),体验更佳!
+访问原文链接:[383. 赎金信 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/383-ransom-note),体验更佳!
-力扣链接:[383. 赎金信](https://leetcode.cn/problems/ransom-note), 难度:**简单**。
+力扣链接:[383. 赎金信](https://leetcode.cn/problems/ransom-note), 难度等级:**简单**。
-## 力扣“383. 赎金信”问题描述
+## LeetCode “383. 赎金信”问题描述
给你两个字符串:`ransomNote` 和 `magazine` ,判断 `ransomNote` 能不能由 `magazine` 里面的字符构成。
@@ -243,10 +243,10 @@ public:
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[383. 赎金信 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/383-ransom-note).
+原文链接:[383. 赎金信 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/383-ransom-note).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/392-is-subsequence.md b/zh/1-1000/392-is-subsequence.md
index 312b6d1..733f551 100644
--- a/zh/1-1000/392-is-subsequence.md
+++ b/zh/1-1000/392-is-subsequence.md
@@ -1,10 +1,10 @@
-# 392. 判断子序列 - 力扣题解最佳实践
+# 392. 判断子序列 - LeetCode Python/Java/C++ 题解
-访问原文链接:[392. 判断子序列 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/392-is-subsequence),体验更佳!
+访问原文链接:[392. 判断子序列 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/392-is-subsequence),体验更佳!
-力扣链接:[392. 判断子序列](https://leetcode.cn/problems/is-subsequence), 难度:**中等**。
+力扣链接:[392. 判断子序列](https://leetcode.cn/problems/is-subsequence), 难度等级:**中等**。
-## 力扣“392. 判断子序列”问题描述
+## LeetCode “392. 判断子序列”问题描述
给定字符串 **s** 和 **t** ,判断 **s** 是否为 **t** 的子序列。
@@ -244,32 +244,32 @@ end
#### “动态规划”分为五步
-1. 确定数组`dp`的每个值代表的含义。
+1. 确定数组`dp`的每个值代表的**含义**。
2. 初始化数组`dp`的值。
-3. 根据一个示例,“按顺序”填入`dp`网格数据。
-4. 根据`dp`网格数据,推导出“递推公式”。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
+4. 根据`dp`网格数据,推导出**递推公式**。
5. 写出程序,并打印`dp`数组,不合预期就调整。
#### 细说这五步
-1. 确定数组`dp`的每个值代表的含义。
- - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个对等数组”,为了理解方便,还是使用“二维数组”。
+1. 确定数组`dp`的每个值代表的**含义**。
+ - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个位置可互换的数组”,为了理解方便,还是使用“二维数组”。
- 尝试使用问题所求的`返回值`的含义作为 `dp[i]`(一维)或`dp[i][j]`(二维)的含义,约60%的概率能行。如果不行,再尝试其他含义。
- 设计上尽量考虑保存更丰富的信息,重复信息只在某个`dp[i]`中保存一次就够了。
- 使用简化的含义。如果用`布尔值`可以解决问题,就不要用`数值`。
2. 初始化数组`dp`的值。`dp`的值涉及两个层面:
1. `dp`的长度。通常是:`条件数组长度加1`或`条件数组长度`。
2. `dp[i]`或`dp[i][j]`的值。`dp[0]`或`dp[0][0]`有时需要特殊处理。
-3. 根据一个示例,“按顺序”填入`dp`网格数据。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
- “递推公式”是“动态规划”算法的核心。但“递推公式”是隐晦的,想得到它,就需要制表,用数据启发自己。
- 如果原示例不够好,需要自己重新设计一个。
- 根据示例,填入`dp`网格数据,需要“按顺序”填,这是很重要的,因为它决定了代码的遍历顺序。
- 大多时候,从左到右,从上到下。但有时需要从右向左、由下而上、从中间向右(或左),如“回文串”问题。有时,还需要一行遍历两次,先正向,再反向。
- 当顺序决定对了,起点就决定好了,从起点出发,“按顺序”填写`dp`网格数据,这也是在模拟程序处理的过程。
- 在此过程中,您将获得写出“递推公式”的灵感。如果您已经能推导出公式,不需要填完网格。
-4. 根据`dp`网格数据,推导出“递推公式”。
+4. 根据`dp`网格数据,推导出**递推公式**。
- 有三个特别的位置需要注意: `dp[i - 1][j - 1]`、`dp[i - 1][j]`和`dp[i][j - 1]`,当前的 `dp[i][j]`往往取决于它们。
- - 操作“两个对等数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
+ - 操作“两个位置可互换的数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
5. 写出程序,并打印`dp`数组,不合预期就调整。
- 重点分析那些不合预期的数值。
@@ -509,10 +509,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[392. 判断子序列 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/392-is-subsequence).
+原文链接:[392. 判断子序列 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/392-is-subsequence).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/416-partition-equal-subset-sum.md b/zh/1-1000/416-partition-equal-subset-sum.md
index 27c0b51..9f56165 100644
--- a/zh/1-1000/416-partition-equal-subset-sum.md
+++ b/zh/1-1000/416-partition-equal-subset-sum.md
@@ -1,10 +1,10 @@
-# 416. 分割等和子集 - 力扣题解最佳实践
+# 416. 分割等和子集 - LeetCode Python/Java/C++ 题解
-访问原文链接:[416. 分割等和子集 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/416-partition-equal-subset-sum),体验更佳!
+访问原文链接:[416. 分割等和子集 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/416-partition-equal-subset-sum),体验更佳!
-力扣链接:[416. 分割等和子集](https://leetcode.cn/problems/partition-equal-subset-sum), 难度:**中等**。
+力扣链接:[416. 分割等和子集](https://leetcode.cn/problems/partition-equal-subset-sum), 难度等级:**中等**。
-## 力扣“416. 分割等和子集”问题描述
+## LeetCode “416. 分割等和子集”问题描述
给你一个 **只包含正整数** 的 **非空** 数组 `nums` 。请你判断是否可以将这个数组分割成两个子集,使得两个子集的元素和相等。
@@ -40,32 +40,32 @@
#### “动态规划”分为五步
-1. 确定数组`dp`的每个值代表的含义。
+1. 确定数组`dp`的每个值代表的**含义**。
2. 初始化数组`dp`的值。
-3. 根据一个示例,“按顺序”填入`dp`网格数据。
-4. 根据`dp`网格数据,推导出“递推公式”。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
+4. 根据`dp`网格数据,推导出**递推公式**。
5. 写出程序,并打印`dp`数组,不合预期就调整。
#### 细说这五步
-1. 确定数组`dp`的每个值代表的含义。
- - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个对等数组”,为了理解方便,还是使用“二维数组”。
+1. 确定数组`dp`的每个值代表的**含义**。
+ - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个位置可互换的数组”,为了理解方便,还是使用“二维数组”。
- 尝试使用问题所求的`返回值`的含义作为 `dp[i]`(一维)或`dp[i][j]`(二维)的含义,约60%的概率能行。如果不行,再尝试其他含义。
- 设计上尽量考虑保存更丰富的信息,重复信息只在某个`dp[i]`中保存一次就够了。
- 使用简化的含义。如果用`布尔值`可以解决问题,就不要用`数值`。
2. 初始化数组`dp`的值。`dp`的值涉及两个层面:
1. `dp`的长度。通常是:`条件数组长度加1`或`条件数组长度`。
2. `dp[i]`或`dp[i][j]`的值。`dp[0]`或`dp[0][0]`有时需要特殊处理。
-3. 根据一个示例,“按顺序”填入`dp`网格数据。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
- “递推公式”是“动态规划”算法的核心。但“递推公式”是隐晦的,想得到它,就需要制表,用数据启发自己。
- 如果原示例不够好,需要自己重新设计一个。
- 根据示例,填入`dp`网格数据,需要“按顺序”填,这是很重要的,因为它决定了代码的遍历顺序。
- 大多时候,从左到右,从上到下。但有时需要从右向左、由下而上、从中间向右(或左),如“回文串”问题。有时,还需要一行遍历两次,先正向,再反向。
- 当顺序决定对了,起点就决定好了,从起点出发,“按顺序”填写`dp`网格数据,这也是在模拟程序处理的过程。
- 在此过程中,您将获得写出“递推公式”的灵感。如果您已经能推导出公式,不需要填完网格。
-4. 根据`dp`网格数据,推导出“递推公式”。
+4. 根据`dp`网格数据,推导出**递推公式**。
- 有三个特别的位置需要注意: `dp[i - 1][j - 1]`、`dp[i - 1][j]`和`dp[i][j - 1]`,当前的 `dp[i][j]`往往取决于它们。
- - 操作“两个对等数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
+ - 操作“两个位置可互换的数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
5. 写出程序,并打印`dp`数组,不合预期就调整。
- 重点分析那些不合预期的数值。
@@ -367,32 +367,32 @@ end
#### “动态规划”分为五步
-1. 确定数组`dp`的每个值代表的含义。
+1. 确定数组`dp`的每个值代表的**含义**。
2. 初始化数组`dp`的值。
-3. 根据一个示例,“按顺序”填入`dp`网格数据。
-4. 根据`dp`网格数据,推导出“递推公式”。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
+4. 根据`dp`网格数据,推导出**递推公式**。
5. 写出程序,并打印`dp`数组,不合预期就调整。
#### 细说这五步
-1. 确定数组`dp`的每个值代表的含义。
- - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个对等数组”,为了理解方便,还是使用“二维数组”。
+1. 确定数组`dp`的每个值代表的**含义**。
+ - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个位置可互换的数组”,为了理解方便,还是使用“二维数组”。
- 尝试使用问题所求的`返回值`的含义作为 `dp[i]`(一维)或`dp[i][j]`(二维)的含义,约60%的概率能行。如果不行,再尝试其他含义。
- 设计上尽量考虑保存更丰富的信息,重复信息只在某个`dp[i]`中保存一次就够了。
- 使用简化的含义。如果用`布尔值`可以解决问题,就不要用`数值`。
2. 初始化数组`dp`的值。`dp`的值涉及两个层面:
1. `dp`的长度。通常是:`条件数组长度加1`或`条件数组长度`。
2. `dp[i]`或`dp[i][j]`的值。`dp[0]`或`dp[0][0]`有时需要特殊处理。
-3. 根据一个示例,“按顺序”填入`dp`网格数据。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
- “递推公式”是“动态规划”算法的核心。但“递推公式”是隐晦的,想得到它,就需要制表,用数据启发自己。
- 如果原示例不够好,需要自己重新设计一个。
- 根据示例,填入`dp`网格数据,需要“按顺序”填,这是很重要的,因为它决定了代码的遍历顺序。
- 大多时候,从左到右,从上到下。但有时需要从右向左、由下而上、从中间向右(或左),如“回文串”问题。有时,还需要一行遍历两次,先正向,再反向。
- 当顺序决定对了,起点就决定好了,从起点出发,“按顺序”填写`dp`网格数据,这也是在模拟程序处理的过程。
- 在此过程中,您将获得写出“递推公式”的灵感。如果您已经能推导出公式,不需要填完网格。
-4. 根据`dp`网格数据,推导出“递推公式”。
+4. 根据`dp`网格数据,推导出**递推公式**。
- 有三个特别的位置需要注意: `dp[i - 1][j - 1]`、`dp[i - 1][j]`和`dp[i][j - 1]`,当前的 `dp[i][j]`往往取决于它们。
- - 操作“两个对等数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
+ - 操作“两个位置可互换的数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
5. 写出程序,并打印`dp`数组,不合预期就调整。
- 重点分析那些不合预期的数值。
@@ -593,10 +593,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[416. 分割等和子集 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/416-partition-equal-subset-sum).
+原文链接:[416. 分割等和子集 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/416-partition-equal-subset-sum).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/454-4sum-ii.md b/zh/1-1000/454-4sum-ii.md
index 4f99863..7c7eaf4 100644
--- a/zh/1-1000/454-4sum-ii.md
+++ b/zh/1-1000/454-4sum-ii.md
@@ -1,10 +1,10 @@
-# 454. 四数相加 II - 力扣题解最佳实践
+# 454. 四数相加 II - LeetCode Python/Java/C++ 题解
-访问原文链接:[454. 四数相加 II - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/454-4sum-ii),体验更佳!
+访问原文链接:[454. 四数相加 II - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/454-4sum-ii),体验更佳!
-力扣链接:[454. 四数相加 II](https://leetcode.cn/problems/4sum-ii), 难度:**中等**。
+力扣链接:[454. 四数相加 II](https://leetcode.cn/problems/4sum-ii), 难度等级:**中等**。
-## 力扣“454. 四数相加 II”问题描述
+## LeetCode “454. 四数相加 II”问题描述
给你四个整数数组 `nums1`、`nums2`、`nums3` 和 `nums4` ,数组长度都是 `n` ,请你计算有多少个元组 `(i, j, k, l)` 能满足:
@@ -271,10 +271,10 @@ public:
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[454. 四数相加 II - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/454-4sum-ii).
+原文链接:[454. 四数相加 II - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/454-4sum-ii).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/459-repeated-substring-pattern.md b/zh/1-1000/459-repeated-substring-pattern.md
index 733ca30..bf837a7 100644
--- a/zh/1-1000/459-repeated-substring-pattern.md
+++ b/zh/1-1000/459-repeated-substring-pattern.md
@@ -1,10 +1,10 @@
-# 459. 重复的子字符串 - 力扣题解最佳实践
+# 459. 重复的子字符串 - LeetCode Python/Java/C++ 题解
-访问原文链接:[459. 重复的子字符串 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/459-repeated-substring-pattern),体验更佳!
+访问原文链接:[459. 重复的子字符串 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/459-repeated-substring-pattern),体验更佳!
-力扣链接:[459. 重复的子字符串](https://leetcode.cn/problems/repeated-substring-pattern), 难度:**简单**。
+力扣链接:[459. 重复的子字符串](https://leetcode.cn/problems/repeated-substring-pattern), 难度等级:**简单**。
-## 力扣“459. 重复的子字符串”问题描述
+## LeetCode “459. 重复的子字符串”问题描述
给定一个非空的字符串 `s` ,检查是否可以通过由它的一个子串重复多次构成。
@@ -220,10 +220,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[459. 重复的子字符串 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/459-repeated-substring-pattern).
+原文链接:[459. 重复的子字符串 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/459-repeated-substring-pattern).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/474-ones-and-zeroes.md b/zh/1-1000/474-ones-and-zeroes.md
index b39a9f2..adb24aa 100644
--- a/zh/1-1000/474-ones-and-zeroes.md
+++ b/zh/1-1000/474-ones-and-zeroes.md
@@ -1,10 +1,10 @@
-# 474. 一和零 - 力扣题解最佳实践
+# 474. 一和零 - LeetCode Python/Java/C++ 题解
-访问原文链接:[474. 一和零 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/474-ones-and-zeroes),体验更佳!
+访问原文链接:[474. 一和零 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/474-ones-and-zeroes),体验更佳!
-力扣链接:[474. 一和零](https://leetcode.cn/problems/ones-and-zeroes), 难度:**中等**。
+力扣链接:[474. 一和零](https://leetcode.cn/problems/ones-and-zeroes), 难度等级:**中等**。
-## 力扣“474. 一和零”问题描述
+## LeetCode “474. 一和零”问题描述
给你一个二进制字符串数组 `strs` 和两个整数 `m` 和 `n` 。
@@ -53,32 +53,32 @@
#### “动态规划”分为五步
-1. 确定数组`dp`的每个值代表的含义。
+1. 确定数组`dp`的每个值代表的**含义**。
2. 初始化数组`dp`的值。
-3. 根据一个示例,“按顺序”填入`dp`网格数据。
-4. 根据`dp`网格数据,推导出“递推公式”。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
+4. 根据`dp`网格数据,推导出**递推公式**。
5. 写出程序,并打印`dp`数组,不合预期就调整。
#### 细说这五步
-1. 确定数组`dp`的每个值代表的含义。
- - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个对等数组”,为了理解方便,还是使用“二维数组”。
+1. 确定数组`dp`的每个值代表的**含义**。
+ - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个位置可互换的数组”,为了理解方便,还是使用“二维数组”。
- 尝试使用问题所求的`返回值`的含义作为 `dp[i]`(一维)或`dp[i][j]`(二维)的含义,约60%的概率能行。如果不行,再尝试其他含义。
- 设计上尽量考虑保存更丰富的信息,重复信息只在某个`dp[i]`中保存一次就够了。
- 使用简化的含义。如果用`布尔值`可以解决问题,就不要用`数值`。
2. 初始化数组`dp`的值。`dp`的值涉及两个层面:
1. `dp`的长度。通常是:`条件数组长度加1`或`条件数组长度`。
2. `dp[i]`或`dp[i][j]`的值。`dp[0]`或`dp[0][0]`有时需要特殊处理。
-3. 根据一个示例,“按顺序”填入`dp`网格数据。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
- “递推公式”是“动态规划”算法的核心。但“递推公式”是隐晦的,想得到它,就需要制表,用数据启发自己。
- 如果原示例不够好,需要自己重新设计一个。
- 根据示例,填入`dp`网格数据,需要“按顺序”填,这是很重要的,因为它决定了代码的遍历顺序。
- 大多时候,从左到右,从上到下。但有时需要从右向左、由下而上、从中间向右(或左),如“回文串”问题。有时,还需要一行遍历两次,先正向,再反向。
- 当顺序决定对了,起点就决定好了,从起点出发,“按顺序”填写`dp`网格数据,这也是在模拟程序处理的过程。
- 在此过程中,您将获得写出“递推公式”的灵感。如果您已经能推导出公式,不需要填完网格。
-4. 根据`dp`网格数据,推导出“递推公式”。
+4. 根据`dp`网格数据,推导出**递推公式**。
- 有三个特别的位置需要注意: `dp[i - 1][j - 1]`、`dp[i - 1][j]`和`dp[i][j - 1]`,当前的 `dp[i][j]`往往取决于它们。
- - 操作“两个对等数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
+ - 操作“两个位置可互换的数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
5. 写出程序,并打印`dp`数组,不合预期就调整。
- 重点分析那些不合预期的数值。
@@ -464,10 +464,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[474. 一和零 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/474-ones-and-zeroes).
+原文链接:[474. 一和零 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/474-ones-and-zeroes).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/49-group-anagrams.md b/zh/1-1000/49-group-anagrams.md
index 38c4e13..a6fc9c6 100644
--- a/zh/1-1000/49-group-anagrams.md
+++ b/zh/1-1000/49-group-anagrams.md
@@ -1,10 +1,10 @@
-# 49. 字母异位词分组 - 力扣题解最佳实践
+# 49. 字母异位词分组 - LeetCode Python/Java/C++ 题解
-访问原文链接:[49. 字母异位词分组 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/49-group-anagrams),体验更佳!
+访问原文链接:[49. 字母异位词分组 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/49-group-anagrams),体验更佳!
-力扣链接:[49. 字母异位词分组](https://leetcode.cn/problems/group-anagrams), 难度:**中等**。
+力扣链接:[49. 字母异位词分组](https://leetcode.cn/problems/group-anagrams), 难度等级:**中等**。
-## 力扣“49. 字母异位词分组”问题描述
+## LeetCode “49. 字母异位词分组”问题描述
给你一个字符串数组,请你将 **字母异位词** 组合在一起。可以按任意顺序返回结果列表。
@@ -102,10 +102,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[49. 字母异位词分组 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/49-group-anagrams).
+原文链接:[49. 字母异位词分组 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/49-group-anagrams).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/494-target-sum.md b/zh/1-1000/494-target-sum.md
index c28b3ab..ab3e56d 100644
--- a/zh/1-1000/494-target-sum.md
+++ b/zh/1-1000/494-target-sum.md
@@ -1,10 +1,10 @@
-# 494. 目标和 - 力扣题解最佳实践
+# 494. 目标和 - LeetCode Python/Java/C++ 题解
-访问原文链接:[494. 目标和 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/494-target-sum),体验更佳!
+访问原文链接:[494. 目标和 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/494-target-sum),体验更佳!
-力扣链接:[494. 目标和](https://leetcode.cn/problems/target-sum), 难度:**中等**。
+力扣链接:[494. 目标和](https://leetcode.cn/problems/target-sum), 难度等级:**中等**。
-## 力扣“494. 目标和”问题描述
+## LeetCode “494. 目标和”问题描述
给你一个非负整数数组 `nums` 和一个整数 `target` 。
@@ -52,32 +52,32 @@
#### “动态规划”分为五步
-1. 确定数组`dp`的每个值代表的含义。
+1. 确定数组`dp`的每个值代表的**含义**。
2. 初始化数组`dp`的值。
-3. 根据一个示例,“按顺序”填入`dp`网格数据。
-4. 根据`dp`网格数据,推导出“递推公式”。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
+4. 根据`dp`网格数据,推导出**递推公式**。
5. 写出程序,并打印`dp`数组,不合预期就调整。
#### 细说这五步
-1. 确定数组`dp`的每个值代表的含义。
- - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个对等数组”,为了理解方便,还是使用“二维数组”。
+1. 确定数组`dp`的每个值代表的**含义**。
+ - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个位置可互换的数组”,为了理解方便,还是使用“二维数组”。
- 尝试使用问题所求的`返回值`的含义作为 `dp[i]`(一维)或`dp[i][j]`(二维)的含义,约60%的概率能行。如果不行,再尝试其他含义。
- 设计上尽量考虑保存更丰富的信息,重复信息只在某个`dp[i]`中保存一次就够了。
- 使用简化的含义。如果用`布尔值`可以解决问题,就不要用`数值`。
2. 初始化数组`dp`的值。`dp`的值涉及两个层面:
1. `dp`的长度。通常是:`条件数组长度加1`或`条件数组长度`。
2. `dp[i]`或`dp[i][j]`的值。`dp[0]`或`dp[0][0]`有时需要特殊处理。
-3. 根据一个示例,“按顺序”填入`dp`网格数据。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
- “递推公式”是“动态规划”算法的核心。但“递推公式”是隐晦的,想得到它,就需要制表,用数据启发自己。
- 如果原示例不够好,需要自己重新设计一个。
- 根据示例,填入`dp`网格数据,需要“按顺序”填,这是很重要的,因为它决定了代码的遍历顺序。
- 大多时候,从左到右,从上到下。但有时需要从右向左、由下而上、从中间向右(或左),如“回文串”问题。有时,还需要一行遍历两次,先正向,再反向。
- 当顺序决定对了,起点就决定好了,从起点出发,“按顺序”填写`dp`网格数据,这也是在模拟程序处理的过程。
- 在此过程中,您将获得写出“递推公式”的灵感。如果您已经能推导出公式,不需要填完网格。
-4. 根据`dp`网格数据,推导出“递推公式”。
+4. 根据`dp`网格数据,推导出**递推公式**。
- 有三个特别的位置需要注意: `dp[i - 1][j - 1]`、`dp[i - 1][j]`和`dp[i][j - 1]`,当前的 `dp[i][j]`往往取决于它们。
- - 操作“两个对等数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
+ - 操作“两个位置可互换的数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
5. 写出程序,并打印`dp`数组,不合预期就调整。
- 重点分析那些不合预期的数值。
@@ -333,10 +333,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[494. 目标和 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/494-target-sum).
+原文链接:[494. 目标和 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/494-target-sum).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/5-longest-palindromic-substring.md b/zh/1-1000/5-longest-palindromic-substring.md
index 50830fe..4b30e8b 100644
--- a/zh/1-1000/5-longest-palindromic-substring.md
+++ b/zh/1-1000/5-longest-palindromic-substring.md
@@ -1,10 +1,10 @@
-# 5. 最长回文子串 - 力扣题解最佳实践
+# 5. 最长回文子串 - LeetCode Python/Java/C++ 题解
-访问原文链接:[5. 最长回文子串 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/5-longest-palindromic-substring),体验更佳!
+访问原文链接:[5. 最长回文子串 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/5-longest-palindromic-substring),体验更佳!
-力扣链接:[5. 最长回文子串](https://leetcode.cn/problems/longest-palindromic-substring), 难度:**中等**。
+力扣链接:[5. 最长回文子串](https://leetcode.cn/problems/longest-palindromic-substring), 难度等级:**中等**。
-## 力扣“5. 最长回文子串”问题描述
+## LeetCode “5. 最长回文子串”问题描述
给你一个字符串 `s`,找到 `s` 中最长的 **回文子串**。
@@ -64,32 +64,32 @@ If we use brute-force and check whether for every start and end position a subst
#### “动态规划”分为五步
-1. 确定数组`dp`的每个值代表的含义。
+1. 确定数组`dp`的每个值代表的**含义**。
2. 初始化数组`dp`的值。
-3. 根据一个示例,“按顺序”填入`dp`网格数据。
-4. 根据`dp`网格数据,推导出“递推公式”。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
+4. 根据`dp`网格数据,推导出**递推公式**。
5. 写出程序,并打印`dp`数组,不合预期就调整。
#### 细说这五步
-1. 确定数组`dp`的每个值代表的含义。
- - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个对等数组”,为了理解方便,还是使用“二维数组”。
+1. 确定数组`dp`的每个值代表的**含义**。
+ - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个位置可互换的数组”,为了理解方便,还是使用“二维数组”。
- 尝试使用问题所求的`返回值`的含义作为 `dp[i]`(一维)或`dp[i][j]`(二维)的含义,约60%的概率能行。如果不行,再尝试其他含义。
- 设计上尽量考虑保存更丰富的信息,重复信息只在某个`dp[i]`中保存一次就够了。
- 使用简化的含义。如果用`布尔值`可以解决问题,就不要用`数值`。
2. 初始化数组`dp`的值。`dp`的值涉及两个层面:
1. `dp`的长度。通常是:`条件数组长度加1`或`条件数组长度`。
2. `dp[i]`或`dp[i][j]`的值。`dp[0]`或`dp[0][0]`有时需要特殊处理。
-3. 根据一个示例,“按顺序”填入`dp`网格数据。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
- “递推公式”是“动态规划”算法的核心。但“递推公式”是隐晦的,想得到它,就需要制表,用数据启发自己。
- 如果原示例不够好,需要自己重新设计一个。
- 根据示例,填入`dp`网格数据,需要“按顺序”填,这是很重要的,因为它决定了代码的遍历顺序。
- 大多时候,从左到右,从上到下。但有时需要从右向左、由下而上、从中间向右(或左),如“回文串”问题。有时,还需要一行遍历两次,先正向,再反向。
- 当顺序决定对了,起点就决定好了,从起点出发,“按顺序”填写`dp`网格数据,这也是在模拟程序处理的过程。
- 在此过程中,您将获得写出“递推公式”的灵感。如果您已经能推导出公式,不需要填完网格。
-4. 根据`dp`网格数据,推导出“递推公式”。
+4. 根据`dp`网格数据,推导出**递推公式**。
- 有三个特别的位置需要注意: `dp[i - 1][j - 1]`、`dp[i - 1][j]`和`dp[i][j - 1]`,当前的 `dp[i][j]`往往取决于它们。
- - 操作“两个对等数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
+ - 操作“两个位置可互换的数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
5. 写出程序,并打印`dp`数组,不合预期就调整。
- 重点分析那些不合预期的数值。
@@ -140,10 +140,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[5. 最长回文子串 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/5-longest-palindromic-substring).
+原文链接:[5. 最长回文子串 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/5-longest-palindromic-substring).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/509-fibonacci-number.md b/zh/1-1000/509-fibonacci-number.md
index 5cfd52b..27a55fa 100644
--- a/zh/1-1000/509-fibonacci-number.md
+++ b/zh/1-1000/509-fibonacci-number.md
@@ -1,52 +1,70 @@
-# 509. Fibonacci Number
-LeetCode link: [509. Fibonacci Number](https://leetcode.com/problems/fibonacci-number/)
+# 509. 斐波那契数 - LeetCode Python/Java/C++ 题解
-## LeetCode problem description
-The **Fibonacci numbers**, commonly denoted `F(n)` form a sequence, called the **Fibonacci sequence**, such that each number is the sum of the two preceding ones, starting from `0` and `1`. That is,
+访问原文链接:[509. 斐波那契数 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/509-fibonacci-number),体验更佳!
-> F(0) = 0, F(1) = 1
-> F(n) = F(n - 1) + F(n - 2), for n > 1.
+力扣链接:[509. 斐波那契数](https://leetcode.cn/problems/fibonacci-number), 难度等级:**简单**。
-Given `n`, calculate `F(n)`.
+## LeetCode “509. 斐波那契数”问题描述
-```
-------------------------------------------------------------------------
-[Example 1]
-
-Input: n = 2
-Output: 1
-Explanation: F(2) = F(1) + F(0) = 1 + 0 = 1.
-------------------------------------------------------------------------
-[Example 2]
-
-Input: n = 3
-Output: 2
-Explanation: F(3) = F(2) + F(1) = 1 + 1 = 2.
-------------------------------------------------------------------------
-[Example 3]
-
-Input: n = 4
-Output: 3
-Explanation: F(4) = F(3) + F(2) = 2 + 1 = 3.
-------------------------------------------------------------------------
-[Constraints]
+**斐波那契数** (通常用 `F(n)` 表示)形成的序列称为 **斐波那契数列** 。该数列由 `0` 和 `1` 开始,后面的每一项数字都是前面两项数字的和。也就是:
+
+> F(0) = 0,F(1) = 1
+> F(n) = F(n - 1) + F(n - 2),其中 n > 1
+
+给定 `n` ,请计算 `F(n)` 。
+
+### [示例 1]
+
+**输入**: `n = 2`
+
+**输出**: `1`
+
+**解释**: `F(2) = F(1) + F(0) = 1 + 0 = 1`
+
+### [示例 2]
+
+**输入**: `n = 3`
+
+**输出**: `2`
+
+**解释**: `F(3) = F(2) + F(1) = 1 + 1 = 2`
+
+### [示例 3]
+
+**输入**: `n = 4`
+
+**输出**: `3`
+
+**解释**: `F(4) = F(3) + F(2) = 2 + 1 = 3`
+
+### [约束]
0 <= n <= 30
-------------------------------------------------------------------------
-```
-## Thoughts
-This problem can be solved using **Dynamic programming**.
+## 思路 1
+
+
+
+## “递归”的模式
+
+递归(Recursion)是计算机科学和数学中的一个重要概念,指的是 一个函数在其定义中 **直接或间接调用自身** 的方法。
+
+### 递归的核心思想
+
+- **自我调用**:函数在执行过程中调用自身。
+- **基线情况**:相当于终止条件。到达基线情况后,就可以返回结果了,不需要再递归调用,防止无限循环。
+- **递归步骤**:问题逐步向“基线情况”靠近的步骤。
+
+## 复杂度
-Detailed solutions will be given later, and now only the best practices in 4 to 7 languages are given.
+> 如果不加用于缓存已知结果的Map,时间复杂度将上升为O( 2^N )
-### Complexity
-* Time: `O(n)`.
-* Space: `O(n)`.
+- 时间复杂度: `O(N)`.
+- 空间复杂度: `O(N)`.
## C#
-### Solution 1: Recursion
-```c#
+
+```csharp
public class Solution {
IDictionary numToFibNum = new Dictionary();
@@ -66,30 +84,180 @@ public class Solution {
}
```
-### Solution 2: Dynamic programming
-```c#
-public class Solution
-{
- public int Fib(int n)
- {
- if (n <= 1)
+## Python
+
+```python
+class Solution:
+ @cache
+ def fib(self, n: int) -> int:
+ if n <= 1:
+ return n
+
+ return self.fib(n - 1) + self.fib(n - 2)
+```
+
+## C++
+
+```cpp
+class Solution {
+public:
+ int fib(int n) {
+ if (n <= 1) {
return n;
+ }
- var dp = new int[n + 1];
- dp[1] = 1;
+ if (num_to_fib_num_.contains(n)) {
+ return num_to_fib_num_[n];
+ }
- for (var i = 2; i < dp.Length; i++)
- {
- dp[i] = dp[i - 1] + dp[i - 2];
+ num_to_fib_num_[n] = fib(n - 1) + fib(n - 2);
+
+ return num_to_fib_num_[n];
+ }
+
+private:
+ unordered_map num_to_fib_num_;
+};
+```
+
+## Java
+
+```java
+class Solution {
+ var numToFibNum = new HashMap();
+
+ public int fib(int n) {
+ if (n <= 1) {
+ return n;
}
- return dp[n];
+ if (numToFibNum.containsKey(n)) {
+ return numToFibNum.get(n);
+ }
+
+ numToFibNum.put(n, fib(n - 1) + fib(n - 2));
+
+ return numToFibNum.get(n);
}
}
```
-### Solution 3: Dynamic programming ('dp.length' is 2)
-```c#
+## JavaScript
+
+```javascript
+const numToFibNum = new Map()
+
+var fib = function (n) {
+ if (n <= 1) {
+ return n
+ }
+
+ if (numToFibNum.has(n)) {
+ return numToFibNum.get(n)
+ }
+
+ numToFibNum.set(n, fib(n - 1) + fib(n - 2))
+
+ return numToFibNum.get(n)
+};
+```
+
+## Go
+
+```go
+func fib(m int) int {
+ numToFibNum := map[int]int{}
+
+ var fibonacci func (int) int
+
+ fibonacci = func (n int) int {
+ if n <= 1 {
+ return n
+ }
+
+ if result, ok := numToFibNum[n]; ok {
+ return result
+ }
+
+ numToFibNum[n] = fibonacci(n - 1) + fibonacci(n - 2)
+ return numToFibNum[n]
+ }
+
+ return fibonacci(m)
+}
+```
+
+## Ruby
+
+```ruby
+def fib(n)
+ return n if n <= 1
+
+ @cache = {} if @cache.nil?
+
+ return @cache[n] if @cache.key?(n)
+
+ @cache[n] = fib(n - 1) + fib(n - 2)
+
+ @cache[n]
+end
+```
+
+## Other languages
+
+```java
+// Welcome to create a PR to complete the code of this language, thanks!
+```
+
+## 思路 2
+
+
+
+## “动态规划”的模式
+
+“动态规划”,需要用`dp`数组来保存结果。`dp[i][j]`的值可以由它的前一个(或多个)值通过公式转化出来。因此,`dp[i][j]`值是一步一步推导出来的,它和先前的`dp`记录值都有联系。
+
+#### “动态规划”分为五步
+
+1. 确定数组`dp`的每个值代表的**含义**。
+2. 初始化数组`dp`的值。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
+4. 根据`dp`网格数据,推导出**递推公式**。
+5. 写出程序,并打印`dp`数组,不合预期就调整。
+
+#### 细说这五步
+
+1. 确定数组`dp`的每个值代表的**含义**。
+ - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个位置可互换的数组”,为了理解方便,还是使用“二维数组”。
+ - 尝试使用问题所求的`返回值`的含义作为 `dp[i]`(一维)或`dp[i][j]`(二维)的含义,约60%的概率能行。如果不行,再尝试其他含义。
+ - 设计上尽量考虑保存更丰富的信息,重复信息只在某个`dp[i]`中保存一次就够了。
+ - 使用简化的含义。如果用`布尔值`可以解决问题,就不要用`数值`。
+2. 初始化数组`dp`的值。`dp`的值涉及两个层面:
+ 1. `dp`的长度。通常是:`条件数组长度加1`或`条件数组长度`。
+ 2. `dp[i]`或`dp[i][j]`的值。`dp[0]`或`dp[0][0]`有时需要特殊处理。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
+ - “递推公式”是“动态规划”算法的核心。但“递推公式”是隐晦的,想得到它,就需要制表,用数据启发自己。
+ - 如果原示例不够好,需要自己重新设计一个。
+ - 根据示例,填入`dp`网格数据,需要“按顺序”填,这是很重要的,因为它决定了代码的遍历顺序。
+ - 大多时候,从左到右,从上到下。但有时需要从右向左、由下而上、从中间向右(或左),如“回文串”问题。有时,还需要一行遍历两次,先正向,再反向。
+ - 当顺序决定对了,起点就决定好了,从起点出发,“按顺序”填写`dp`网格数据,这也是在模拟程序处理的过程。
+ - 在此过程中,您将获得写出“递推公式”的灵感。如果您已经能推导出公式,不需要填完网格。
+4. 根据`dp`网格数据,推导出**递推公式**。
+ - 有三个特别的位置需要注意: `dp[i - 1][j - 1]`、`dp[i - 1][j]`和`dp[i][j - 1]`,当前的 `dp[i][j]`往往取决于它们。
+ - 操作“两个位置可互换的数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
+5. 写出程序,并打印`dp`数组,不合预期就调整。
+ - 重点分析那些不合预期的数值。
+
+读完了上面的内容,是不是感觉“动态规划”也没有那么难了?试着解出这道题吧。🤗
+
+## 复杂度
+
+- 时间复杂度: `O(N)`.
+- 空间复杂度: `O(N)`.
+
+## C#
+
+```csharp
public class Solution
{
public int Fib(int n)
@@ -97,34 +265,21 @@ public class Solution
if (n <= 1)
return n;
- int[] dp = [0, 1];
+ var dp = new int[n + 1];
+ dp[1] = 1;
- for (var i = 2; i <= n; i++)
+ for (var i = 2; i < dp.Length; i++)
{
- var dc = (int[])dp.Clone();
-
- dp[0] = dc[1];
- dp[1] = dc[0] + dc[1];
+ dp[i] = dp[i - 1] + dp[i - 2];
}
- return dp[1];
+ return dp[n];
}
}
```
## Python
-### Solution 1: Recursion
-```python
-class Solution:
- @cache
- def fib(self, n: int) -> int:
- if n <= 1:
- return n
-
- return self.fib(n - 1) + self.fib(n - 2)
-```
-### Solution 2: Dynamic programming
```python
class Solution:
def fib(self, n: int) -> int:
@@ -140,26 +295,8 @@ class Solution:
return dp[-1]
```
-### Solution 3: Dynamic programming ('dp.length' is 2)
-```python
-class Solution:
- def fib(self, n: int) -> int:
- if n == 0:
- return 0
-
- dp = [0, 1]
-
- for i in range(2, n + 1):
- dc = dp.copy()
-
- dp[0] = dc[1]
- dp[1] = dc[0] + dc[1]
-
- return dp[1]
-```
-
## C++
-### Solution 1: Recursion
+
```cpp
class Solution {
public:
@@ -168,54 +305,161 @@ public:
return n;
}
- if (num_to_fib_num_.contains(n)) {
- return num_to_fib_num_[n];
- }
+ auto dp = vector(n + 1);
+ dp[1] = 1;
- num_to_fib_num_[n] = fib(n - 1) + fib(n - 2);
+ for (auto i = 2; i < dp.size(); i++) {
+ dp[i] = dp[i - 1] + dp[i - 2];
+ }
- return num_to_fib_num_[n];
+ return dp[n];
}
-
-private:
- unordered_map num_to_fib_num_;
};
```
-### Solution 2: Dynamic programming
-```c++
+## Java
+
+```java
class Solution {
-public:
- int fib(int n) {
+ public int fib(int n) {
if (n <= 1) {
return n;
}
- auto dp = vector(n + 1);
+ var dp = new int[n + 1];
dp[1] = 1;
- for (auto i = 2; i < dp.size(); i++) {
+ for (var i = 2; i < dp.length; i++) {
dp[i] = dp[i - 1] + dp[i - 2];
}
return dp[n];
}
+}
+```
+
+## JavaScript
+
+```javascript
+var fib = function (n) {
+ if (n <= 1) {
+ return n
+ }
+
+ const dp = Array(n + 1).fill(0)
+ dp[1] = 1
+
+ for (let i = 2; i < dp.length; i++) {
+ dp[i] = dp[i - 1] + dp[i - 2]
+ }
+
+ return dp[n]
};
```
-### Solution 3: Dynamic programming ('dp.length' is 2)
-```c++
-class Solution {
-public:
- int fib(int n) {
- if (n <= 1) {
+## Go
+
+```go
+func fib(n int) int {
+ if n == 0 {
+ return 0
+ }
+
+ dp := make([]int, n + 1)
+ dp[1] = 1
+
+ for i := 2; i <= n; i++ {
+ dp[i] = dp[i - 2] + dp[i - 1]
+ }
+
+ return dp[n]
+}
+```
+
+## Ruby
+
+```ruby
+def fib(n)
+ return 0 if n == 0
+
+ dp = Array.new(n + 1, 0)
+ dp[1] = 1
+
+ (2...dp.size).each do |i|
+ dp[i] = dp[i - 1] + dp[i - 2]
+ end
+
+ dp[-1]
+end
+```
+
+## Other languages
+
+```java
+// Welcome to create a PR to complete the code of this language, thanks!
+```
+
+## 思路 3
+
+
+
+## “动态规划”的模式
+
+“动态规划”,需要用`dp`数组来保存结果。`dp[i][j]`的值可以由它的前一个(或多个)值通过公式转化出来。因此,`dp[i][j]`值是一步一步推导出来的,它和先前的`dp`记录值都有联系。
+
+#### “动态规划”分为五步
+
+1. 确定数组`dp`的每个值代表的**含义**。
+2. 初始化数组`dp`的值。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
+4. 根据`dp`网格数据,推导出**递推公式**。
+5. 写出程序,并打印`dp`数组,不合预期就调整。
+
+#### 细说这五步
+
+1. 确定数组`dp`的每个值代表的**含义**。
+ - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个位置可互换的数组”,为了理解方便,还是使用“二维数组”。
+ - 尝试使用问题所求的`返回值`的含义作为 `dp[i]`(一维)或`dp[i][j]`(二维)的含义,约60%的概率能行。如果不行,再尝试其他含义。
+ - 设计上尽量考虑保存更丰富的信息,重复信息只在某个`dp[i]`中保存一次就够了。
+ - 使用简化的含义。如果用`布尔值`可以解决问题,就不要用`数值`。
+2. 初始化数组`dp`的值。`dp`的值涉及两个层面:
+ 1. `dp`的长度。通常是:`条件数组长度加1`或`条件数组长度`。
+ 2. `dp[i]`或`dp[i][j]`的值。`dp[0]`或`dp[0][0]`有时需要特殊处理。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
+ - “递推公式”是“动态规划”算法的核心。但“递推公式”是隐晦的,想得到它,就需要制表,用数据启发自己。
+ - 如果原示例不够好,需要自己重新设计一个。
+ - 根据示例,填入`dp`网格数据,需要“按顺序”填,这是很重要的,因为它决定了代码的遍历顺序。
+ - 大多时候,从左到右,从上到下。但有时需要从右向左、由下而上、从中间向右(或左),如“回文串”问题。有时,还需要一行遍历两次,先正向,再反向。
+ - 当顺序决定对了,起点就决定好了,从起点出发,“按顺序”填写`dp`网格数据,这也是在模拟程序处理的过程。
+ - 在此过程中,您将获得写出“递推公式”的灵感。如果您已经能推导出公式,不需要填完网格。
+4. 根据`dp`网格数据,推导出**递推公式**。
+ - 有三个特别的位置需要注意: `dp[i - 1][j - 1]`、`dp[i - 1][j]`和`dp[i][j - 1]`,当前的 `dp[i][j]`往往取决于它们。
+ - 操作“两个位置可互换的数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
+5. 写出程序,并打印`dp`数组,不合预期就调整。
+ - 重点分析那些不合预期的数值。
+
+读完了上面的内容,是不是感觉“动态规划”也没有那么难了?试着解出这道题吧。🤗
+
+## 复杂度
+
+- 时间复杂度: `O(N)`.
+- 空间复杂度: `O(1)`.
+
+## C#
+
+```csharp
+public class Solution
+{
+ public int Fib(int n)
+ {
+ if (n <= 1)
return n;
- }
- vector dp = {0, 1};
+ int[] dp = [0, 1];
- for (auto i = 2; i <= n; i++) {
- auto dc = dp;
+ for (var i = 2; i <= n; i++)
+ {
+ var dc = (int[])dp.Clone();
dp[0] = dc[1];
dp[1] = dc[0] + dc[1];
@@ -223,52 +467,54 @@ public:
return dp[1];
}
-};
+}
```
-## Java
-### Solution 1: Recursion
-```java
-class Solution {
- var numToFibNum = new HashMap();
+## Python
- public int fib(int n) {
- if (n <= 1) {
- return n;
- }
+```python
+class Solution:
+ def fib(self, n: int) -> int:
+ if n == 0:
+ return 0
- if (numToFibNum.containsKey(n)) {
- return numToFibNum.get(n);
- }
+ dp = [0, 1]
- numToFibNum.put(n, fib(n - 1) + fib(n - 2));
+ for i in range(2, n + 1):
+ dc = dp.copy()
- return numToFibNum.get(n);
- }
-}
+ dp[0] = dc[1]
+ dp[1] = dc[0] + dc[1]
+
+ return dp[1]
```
-### Solution 2: Dynamic programming
-```java
+## C++
+
+```cpp
class Solution {
- public int fib(int n) {
+public:
+ int fib(int n) {
if (n <= 1) {
return n;
}
- var dp = new int[n + 1];
- dp[1] = 1;
+ vector dp = {0, 1};
- for (var i = 2; i < dp.length; i++) {
- dp[i] = dp[i - 1] + dp[i - 2];
+ for (auto i = 2; i <= n; i++) {
+ auto dc = dp;
+
+ dp[0] = dc[1];
+ dp[1] = dc[0] + dc[1];
}
- return dp[n];
+ return dp[1];
}
-}
+};
```
-### Solution 3: Dynamic programming ('dp.length' is 2)
+## Java
+
```java
class Solution {
public int fib(int n) {
@@ -291,44 +537,7 @@ class Solution {
```
## JavaScript
-### Solution 1: Recursion
-```javascript
-const numToFibNum = new Map()
-var fib = function (n) {
- if (n <= 1) {
- return n
- }
-
- if (numToFibNum.has(n)) {
- return numToFibNum.get(n)
- }
-
- numToFibNum.set(n, fib(n - 1) + fib(n - 2))
-
- return numToFibNum.get(n)
-};
-```
-
-### Solution 2: Dynamic programming
-```javascript
-var fib = function (n) {
- if (n <= 1) {
- return n
- }
-
- const dp = Array(n + 1).fill(0)
- dp[1] = 1
-
- for (let i = 2; i < dp.length; i++) {
- dp[i] = dp[i - 1] + dp[i - 2]
- }
-
- return dp[n]
-};
-```
-
-### Solution 3: Dynamic programming ('dp.length' is 2)
```javascript
var fib = function (n) {
if (n <= 1) {
@@ -349,49 +558,7 @@ var fib = function (n) {
```
## Go
-### Solution 1: Recursion
-```go
-func fib(m int) int {
- numToFibNum := map[int]int{}
-
- var fibonacci func (int) int
-
- fibonacci = func (n int) int {
- if n <= 1 {
- return n
- }
- if result, ok := numToFibNum[n]; ok {
- return result
- }
-
- numToFibNum[n] = fibonacci(n - 1) + fibonacci(n - 2)
- return numToFibNum[n]
- }
-
- return fibonacci(m)
-}
-```
-
-### Solution 2: Dynamic programming
-```go
-func fib(n int) int {
- if n == 0 {
- return 0
- }
-
- dp := make([]int, n + 1)
- dp[1] = 1
-
- for i := 2; i <= n; i++ {
- dp[i] = dp[i - 2] + dp[i - 1]
- }
-
- return dp[n]
-}
-```
-
-### Solution 3: Dynamic programming ('dp.length' is 2)
```go
func fib(n int) int {
if n == 0 {
@@ -412,38 +579,7 @@ func fib(n int) int {
```
## Ruby
-### Solution 1: Recursion
-```ruby
-def fib(n)
- return n if n <= 1
-
- @cache = {} if @cache.nil?
-
- return @cache[n] if @cache.key?(n)
-
- @cache[n] = fib(n - 1) + fib(n - 2)
-
- @cache[n]
-end
-```
-
-### Solution 2: Dynamic programming
-```ruby
-def fib(n)
- return 0 if n == 0
-
- dp = Array.new(n + 1, 0)
- dp[1] = 1
-
- (2...dp.size).each do |i|
- dp[i] = dp[i - 1] + dp[i - 2]
- end
-
- dp[-1]
-end
-```
-### Solution 3: Dynamic programming ('dp.length' is 2)
```ruby
def fib(n)
return 0 if n == 0
@@ -461,12 +597,16 @@ def fib(n)
end
```
-## Rust
-```rust
-// Welcome to create a PR to complete the code of this language, thanks!
-```
-
## Other languages
-```
+
+```java
// Welcome to create a PR to complete the code of this language, thanks!
```
+
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
+本站敢称力扣题解最佳实践,终将省你大量刷题时间!
+
+原文链接:[509. 斐波那契数 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/509-fibonacci-number).
+
+GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
+
diff --git a/zh/1-1000/53-maximum-subarray.md b/zh/1-1000/53-maximum-subarray.md
index 2ff72c1..a98e387 100644
--- a/zh/1-1000/53-maximum-subarray.md
+++ b/zh/1-1000/53-maximum-subarray.md
@@ -1,10 +1,10 @@
-# 53. 最大子数组和 - 力扣题解最佳实践
+# 53. 最大子数组和 - LeetCode Python/Java/C++ 题解
-访问原文链接:[53. 最大子数组和 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/53-maximum-subarray),体验更佳!
+访问原文链接:[53. 最大子数组和 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/53-maximum-subarray),体验更佳!
-力扣链接:[53. 最大子数组和](https://leetcode.cn/problems/maximum-subarray), 难度:**中等**。
+力扣链接:[53. 最大子数组和](https://leetcode.cn/problems/maximum-subarray), 难度等级:**中等**。
-## 力扣“53. 最大子数组和”问题描述
+## LeetCode “53. 最大子数组和”问题描述
给你一个整数数组 `nums` ,请你找出一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。
@@ -56,32 +56,32 @@
#### “动态规划”分为五步
-1. 确定数组`dp`的每个值代表的含义。
+1. 确定数组`dp`的每个值代表的**含义**。
2. 初始化数组`dp`的值。
-3. 根据一个示例,“按顺序”填入`dp`网格数据。
-4. 根据`dp`网格数据,推导出“递推公式”。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
+4. 根据`dp`网格数据,推导出**递推公式**。
5. 写出程序,并打印`dp`数组,不合预期就调整。
#### 细说这五步
-1. 确定数组`dp`的每个值代表的含义。
- - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个对等数组”,为了理解方便,还是使用“二维数组”。
+1. 确定数组`dp`的每个值代表的**含义**。
+ - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个位置可互换的数组”,为了理解方便,还是使用“二维数组”。
- 尝试使用问题所求的`返回值`的含义作为 `dp[i]`(一维)或`dp[i][j]`(二维)的含义,约60%的概率能行。如果不行,再尝试其他含义。
- 设计上尽量考虑保存更丰富的信息,重复信息只在某个`dp[i]`中保存一次就够了。
- 使用简化的含义。如果用`布尔值`可以解决问题,就不要用`数值`。
2. 初始化数组`dp`的值。`dp`的值涉及两个层面:
1. `dp`的长度。通常是:`条件数组长度加1`或`条件数组长度`。
2. `dp[i]`或`dp[i][j]`的值。`dp[0]`或`dp[0][0]`有时需要特殊处理。
-3. 根据一个示例,“按顺序”填入`dp`网格数据。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
- “递推公式”是“动态规划”算法的核心。但“递推公式”是隐晦的,想得到它,就需要制表,用数据启发自己。
- 如果原示例不够好,需要自己重新设计一个。
- 根据示例,填入`dp`网格数据,需要“按顺序”填,这是很重要的,因为它决定了代码的遍历顺序。
- 大多时候,从左到右,从上到下。但有时需要从右向左、由下而上、从中间向右(或左),如“回文串”问题。有时,还需要一行遍历两次,先正向,再反向。
- 当顺序决定对了,起点就决定好了,从起点出发,“按顺序”填写`dp`网格数据,这也是在模拟程序处理的过程。
- 在此过程中,您将获得写出“递推公式”的灵感。如果您已经能推导出公式,不需要填完网格。
-4. 根据`dp`网格数据,推导出“递推公式”。
+4. 根据`dp`网格数据,推导出**递推公式**。
- 有三个特别的位置需要注意: `dp[i - 1][j - 1]`、`dp[i - 1][j]`和`dp[i][j - 1]`,当前的 `dp[i][j]`往往取决于它们。
- - 操作“两个对等数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
+ - 操作“两个位置可互换的数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
5. 写出程序,并打印`dp`数组,不合预期就调整。
- 重点分析那些不合预期的数值。
@@ -388,10 +388,10 @@ class Solution {
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[53. 最大子数组和 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/53-maximum-subarray).
+原文链接:[53. 最大子数组和 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/53-maximum-subarray).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/541-reverse-string-ii.md b/zh/1-1000/541-reverse-string-ii.md
index 3b98814..3df4939 100644
--- a/zh/1-1000/541-reverse-string-ii.md
+++ b/zh/1-1000/541-reverse-string-ii.md
@@ -1,10 +1,10 @@
-# 541. 反转字符串 II - 力扣题解最佳实践
+# 541. 反转字符串 II - LeetCode Python/Java/C++ 题解
-访问原文链接:[541. 反转字符串 II - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/541-reverse-string-ii),体验更佳!
+访问原文链接:[541. 反转字符串 II - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/541-reverse-string-ii),体验更佳!
-力扣链接:[541. 反转字符串 II](https://leetcode.cn/problems/reverse-string-ii), 难度:**简单**。
+力扣链接:[541. 反转字符串 II](https://leetcode.cn/problems/reverse-string-ii), 难度等级:**简单**。
-## 力扣“541. 反转字符串 II”问题描述
+## LeetCode “541. 反转字符串 II”问题描述
给定一个字符串 `s` 和一个整数 `k`,从字符串开头算起,每计数至 `2k` 个字符,就反转这 `2k` 字符中的前 `k` 个字符。
@@ -276,10 +276,10 @@ func reverseStr(s string, k int) string {
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[541. 反转字符串 II - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/541-reverse-string-ii).
+原文链接:[541. 反转字符串 II - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/541-reverse-string-ii).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/583-delete-operation-for-two-strings.md b/zh/1-1000/583-delete-operation-for-two-strings.md
index 342df76..6263369 100644
--- a/zh/1-1000/583-delete-operation-for-two-strings.md
+++ b/zh/1-1000/583-delete-operation-for-two-strings.md
@@ -1,10 +1,10 @@
-# 583. 两个字符串的删除操作 - 力扣题解最佳实践
+# 583. 两个字符串的删除操作 - LeetCode Python/Java/C++ 题解
-访问原文链接:[583. 两个字符串的删除操作 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/583-delete-operation-for-two-strings),体验更佳!
+访问原文链接:[583. 两个字符串的删除操作 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/583-delete-operation-for-two-strings),体验更佳!
-力扣链接:[583. 两个字符串的删除操作](https://leetcode.cn/problems/delete-operation-for-two-strings), 难度:**中等**。
+力扣链接:[583. 两个字符串的删除操作](https://leetcode.cn/problems/delete-operation-for-two-strings), 难度等级:**中等**。
-## 力扣“583. 两个字符串的删除操作”问题描述
+## LeetCode “583. 两个字符串的删除操作”问题描述
给定两个单词 `word1` 和 `word2` ,返回使得 `word1` 和 `word2` 相同所需的最小步数。
@@ -40,32 +40,32 @@
#### “动态规划”分为五步
-1. 确定数组`dp`的每个值代表的含义。
+1. 确定数组`dp`的每个值代表的**含义**。
2. 初始化数组`dp`的值。
-3. 根据一个示例,“按顺序”填入`dp`网格数据。
-4. 根据`dp`网格数据,推导出“递推公式”。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
+4. 根据`dp`网格数据,推导出**递推公式**。
5. 写出程序,并打印`dp`数组,不合预期就调整。
#### 细说这五步
-1. 确定数组`dp`的每个值代表的含义。
- - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个对等数组”,为了理解方便,还是使用“二维数组”。
+1. 确定数组`dp`的每个值代表的**含义**。
+ - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个位置可互换的数组”,为了理解方便,还是使用“二维数组”。
- 尝试使用问题所求的`返回值`的含义作为 `dp[i]`(一维)或`dp[i][j]`(二维)的含义,约60%的概率能行。如果不行,再尝试其他含义。
- 设计上尽量考虑保存更丰富的信息,重复信息只在某个`dp[i]`中保存一次就够了。
- 使用简化的含义。如果用`布尔值`可以解决问题,就不要用`数值`。
2. 初始化数组`dp`的值。`dp`的值涉及两个层面:
1. `dp`的长度。通常是:`条件数组长度加1`或`条件数组长度`。
2. `dp[i]`或`dp[i][j]`的值。`dp[0]`或`dp[0][0]`有时需要特殊处理。
-3. 根据一个示例,“按顺序”填入`dp`网格数据。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
- “递推公式”是“动态规划”算法的核心。但“递推公式”是隐晦的,想得到它,就需要制表,用数据启发自己。
- 如果原示例不够好,需要自己重新设计一个。
- 根据示例,填入`dp`网格数据,需要“按顺序”填,这是很重要的,因为它决定了代码的遍历顺序。
- 大多时候,从左到右,从上到下。但有时需要从右向左、由下而上、从中间向右(或左),如“回文串”问题。有时,还需要一行遍历两次,先正向,再反向。
- 当顺序决定对了,起点就决定好了,从起点出发,“按顺序”填写`dp`网格数据,这也是在模拟程序处理的过程。
- 在此过程中,您将获得写出“递推公式”的灵感。如果您已经能推导出公式,不需要填完网格。
-4. 根据`dp`网格数据,推导出“递推公式”。
+4. 根据`dp`网格数据,推导出**递推公式**。
- 有三个特别的位置需要注意: `dp[i - 1][j - 1]`、`dp[i - 1][j]`和`dp[i][j - 1]`,当前的 `dp[i][j]`往往取决于它们。
- - 操作“两个对等数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
+ - 操作“两个位置可互换的数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
5. 写出程序,并打印`dp`数组,不合预期就调整。
- 重点分析那些不合预期的数值。
@@ -327,10 +327,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[583. 两个字符串的删除操作 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/583-delete-operation-for-two-strings).
+原文链接:[583. 两个字符串的删除操作 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/583-delete-operation-for-two-strings).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/59-spiral-matrix-ii.md b/zh/1-1000/59-spiral-matrix-ii.md
index 557eef3..563660e 100644
--- a/zh/1-1000/59-spiral-matrix-ii.md
+++ b/zh/1-1000/59-spiral-matrix-ii.md
@@ -1,10 +1,10 @@
-# 59. 螺旋矩阵 II - 力扣题解最佳实践
+# 59. 螺旋矩阵 II - LeetCode Python/Java/C++ 题解
-访问原文链接:[59. 螺旋矩阵 II - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/59-spiral-matrix-ii),体验更佳!
+访问原文链接:[59. 螺旋矩阵 II - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/59-spiral-matrix-ii),体验更佳!
-力扣链接:[59. 螺旋矩阵 II](https://leetcode.cn/problems/spiral-matrix-ii), 难度:**中等**。
+力扣链接:[59. 螺旋矩阵 II](https://leetcode.cn/problems/spiral-matrix-ii), 难度等级:**中等**。
-## 力扣“59. 螺旋矩阵 II”问题描述
+## LeetCode “59. 螺旋矩阵 II”问题描述
给你一个正整数 `n` ,生成一个包含 *1* 到 *n2* 所有元素,且元素按顺时针顺序螺旋排列的 `n x n` 正方形矩阵 `matrix` 。
@@ -408,10 +408,10 @@ private:
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[59. 螺旋矩阵 II - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/59-spiral-matrix-ii).
+原文链接:[59. 螺旋矩阵 II - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/59-spiral-matrix-ii).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/704-binary-search.md b/zh/1-1000/704-binary-search.md
index 0c4dc7f..af3cf86 100644
--- a/zh/1-1000/704-binary-search.md
+++ b/zh/1-1000/704-binary-search.md
@@ -1,10 +1,10 @@
-# 704. 二分查找 - 力扣题解最佳实践
+# 704. 二分查找 - LeetCode Python/Java/C++ 题解
-访问原文链接:[704. 二分查找 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/704-binary-search),体验更佳!
+访问原文链接:[704. 二分查找 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/704-binary-search),体验更佳!
-力扣链接:[704. 二分查找](https://leetcode.cn/problems/binary-search), 难度:**简单**。
+力扣链接:[704. 二分查找](https://leetcode.cn/problems/binary-search), 难度等级:**简单**。
-## 力扣“704. 二分查找”问题描述
+## LeetCode “704. 二分查找”问题描述
给定一个 `n` 个元素有序的(升序)整型数组 `nums` 和一个目标值 `target` ,写一个函数搜索 `nums` 中的 `target`,如果目标值存在返回下标,否则返回 `-1`。
@@ -234,10 +234,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[704. 二分查找 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/704-binary-search).
+原文链接:[704. 二分查找 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/704-binary-search).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/707-design-linked-list.md b/zh/1-1000/707-design-linked-list.md
index 0cca1eb..341f97e 100644
--- a/zh/1-1000/707-design-linked-list.md
+++ b/zh/1-1000/707-design-linked-list.md
@@ -1,10 +1,10 @@
-# 707. 设计链表 - 力扣题解最佳实践
+# 707. 设计链表 - LeetCode Python/Java/C++ 题解
-访问原文链接:[707. 设计链表 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/707-design-linked-list),体验更佳!
+访问原文链接:[707. 设计链表 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/707-design-linked-list),体验更佳!
-力扣链接:[707. 设计链表](https://leetcode.cn/problems/design-linked-list), 难度:**中等**。
+力扣链接:[707. 设计链表](https://leetcode.cn/problems/design-linked-list), 难度等级:**中等**。
-## 力扣“707. 设计链表”问题描述
+## LeetCode “707. 设计链表”问题描述
你可以选择使用单链表或者双链表,设计并实现自己的链表。
@@ -632,10 +632,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[707. 设计链表 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/707-design-linked-list).
+原文链接:[707. 设计链表 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/707-design-linked-list).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/72-edit-distance.md b/zh/1-1000/72-edit-distance.md
index ebedd9f..60e65c6 100644
--- a/zh/1-1000/72-edit-distance.md
+++ b/zh/1-1000/72-edit-distance.md
@@ -1,136 +1,182 @@
-# 72. Edit Distance (Dynamic Programming Solution)
-LeetCode link: [72. Edit Distance](https://leetcode.com/problems/edit-distance/)
+# 72. 编辑距离 - LeetCode Python/Java/C++ 题解
-## LeetCode problem description
-> Given two strings `word1` and `word2`, return the **minimum** number of operations required to convert `word1` to `word2`.
+访问原文链接:[72. 编辑距离 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/72-edit-distance),体验更佳!
-You have the following three operations permitted on a word:
-- Insert a character
-- Delete a character
-- Replace a character
+力扣链接:[72. 编辑距离](https://leetcode.cn/problems/edit-distance), 难度等级:**中等**。
-```
-Example 1:
+## LeetCode “72. 编辑距离”问题描述
-Input: word1 = "horse", word2 = "ros"
-Output: 3
+给你两个单词 `word1` 和 `word2`, 请返回将 `word1` 转换成 `word2` 所使用的**最少操作数**。
-Explanation:
-horse -> rorse (replace 'h' with 'r')
-rorse -> rose (remove 'r')
-rose -> ros (remove 'e')
--------------------------------------------------------
+你可以对一个单词进行如下三种操作:
-Example 2:
+- 插入一个字符
+- 删除一个字符
+- 替换一个字符
-Input: word1 = "intention", word2 = "execution"
-Output: 5
+### [示例 1]
-Explanation:
-intention -> inention (remove 't')
-inention -> enention (replace 'i' with 'e')
-enention -> exention (replace 'n' with 'x')
-exention -> exection (replace 'n' with 'c')
-exection -> execution (insert 'u')
--------------------------------------------------------
+**输入**: `word1 = "horse", word2 = "ros"`
-Constraints:
+**输出**: `3`
-1. 0 <= word1.length, word2.length <= 500
-2. `word1` and `word2` consist of lowercase English letters.
-```
+**解释**:
+
+horse -> rorse (将 'h' 替换为 'r')
+rorse -> rose (删除 'r')
+rose -> ros (删除 'e')
+
+
+### [示例 2]
+
+**输入**: `word1 = "intention", word2 = "execution"`
+
+**输出**: `5`
+
+**解释**:
-## Thoughts
-* It is a question of comparing two strings. After doing similar questions many times, we will develop an intuition to use dynamic programming with two-dimensional arrays.
-
-### Common steps in dynamic programming
-These five steps are a pattern for solving `dynamic programming` problems.
-
-1. Determine the **meaning** of the `dp[i][j]`
- * Since there are two strings, we can use two-dimensional arrays as the default option.
- * At first, try to use the problem's `return` value as the value of `dp[i][j]` to determine the meaning of `dp[i][j]`. If it doesn't work, try another way.
- * `dp[i][j]` represents the **minimum** number of operations required to convert `word1`'s first `i` letters to `word2`'s first `j` letters.
- * `dp[i][j]` is an integer.
-2. Determine the `dp` array's initial value
- * Use an example:
- ```
- After initialization, the 'dp' array would be:
- # r o s
- # 0 1 2 3 # dp[0]
- # h 1 0 0 0
- # o 2 0 0 0
- # r 3 0 0 0
- # s 4 0 0 0
- # e 5 0 0 0
- ```
- * `dp[i][0] = i`, because `dp[i][0]` represents the empty string, and the number of operations is just the number of chars to be deleted.
- * `dp[0][j] = j`, the reason is the same as the previous line, just viewed from the opposite angle: convert `word2` to `word1`.
-
-3. Determine the `dp` array's recurrence formula
- * Try to complete the `dp` grid. In the process, you will get inspiration to derive the formula.
- ```
- 1. Convert `h` to `ros`.
- # r o s
- # 0 1 2 3
- # h 1 1 2 3 # dp[1]
- ```
- ```
- 2. Convert `ho` to `ros`.
- # r o s
- # 0 1 2 3
- # h 1 1 2 3
- # o 2 2 1 2
- ```
- ```
- 3. Convert `hor` to `ros`.
- # r o s
- # 0 1 2 3
- # h 1 1 2 3
- # o 2 2 1 2
- # r 3 2 2 2
- ```
- ```
- 4. Convert `hors` to `ros`.
- # r o s
- # 0 1 2 3
- # h 1 1 2 3
- # o 2 2 1 2
- # r 3 2 2 2
- # s 4 3 3 2
- ```
- ```
- 5. Convert `horse` to `ros`.
- # r o s
- # 0 1 2 3
- # h 1 1 2 3
- # o 2 2 1 2
- # r 3 2 2 2
- # s 4 3 3 2
- # e 5 4 4 3 # dp[5]
- ```
- * When analyzing the sample `dp` grid, remember there are three important points which you should pay special attention to: `dp[i - 1][j - 1]`, `dp[i - 1][j]` and `dp[i][j - 1]`. The current `dp[i][j]` often depends on them.
- * If the question is also true in reverse (swap `word1` and `word2`), and we need to use `dp[i - 1][j]` or `dp[i][j - 1]`, then we probably need to use both of them.
- * We can derive the `Recurrence Formula`:
- ```python
- if word1[i - 1] == word2[j - 1]
- dp[i][j] = dp[i - 1][j - 1]
- else
- dp[i][j] = min(
- dp[i - 1][j - 1],
- dp[i - 1][j],
- dp[i][j - 1],
- ) + 1
- ```
-4. Determine the `dp` array's traversal order
- * `dp[i][j]` depends on `dp[i - 1][j - 1]`, `dp[i - 1][j]` and `dp[i][j - 1]`, so we should traverse the `dp` array from top to bottom, then from left to right.
-5. Check the `dp` array's value
- * Print the `dp` to see if it is as expected.
-
-### Complexity
-* Time: `O(n * m)`.
-* Space: `O(n * m)`.
+intention -> inention (删除 't')
+inention -> enention (将 'i' 替换为 'e')
+enention -> exention (将 'n' 替换为 'x')
+exention -> exection (将 'n' 替换为 'c')
+exection -> execution (插入 'u')
+
+
+### [约束]
+
+1. `0 <= word1.length, word2.length <= 500`
+2. `word1` 和 `word2` 由小写英文字母组成
+
+## 思路
+
+这是一道比较两个字符串的题目。在多次练习类似的题目之后,我们能培养出使用*二维*数组`dp`的“动态规划”方法解决本问题的直觉。
+
+## “动态规划”的模式
+
+“动态规划”,需要用`dp`数组来保存结果。`dp[i][j]`的值可以由它的前一个(或多个)值通过公式转化出来。因此,`dp[i][j]`值是一步一步推导出来的,它和先前的`dp`记录值都有联系。
+
+#### “动态规划”分为五步
+
+1. 确定数组`dp`的每个值代表的**含义**。
+2. 初始化数组`dp`的值。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
+4. 根据`dp`网格数据,推导出**递推公式**。
+5. 写出程序,并打印`dp`数组,不合预期就调整。
+
+#### 细说这五步
+
+1. 确定数组`dp`的每个值代表的**含义**。
+ - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个位置可互换的数组”,为了理解方便,还是使用“二维数组”。
+ - 尝试使用问题所求的`返回值`的含义作为 `dp[i]`(一维)或`dp[i][j]`(二维)的含义,约60%的概率能行。如果不行,再尝试其他含义。
+ - 设计上尽量考虑保存更丰富的信息,重复信息只在某个`dp[i]`中保存一次就够了。
+ - 使用简化的含义。如果用`布尔值`可以解决问题,就不要用`数值`。
+2. 初始化数组`dp`的值。`dp`的值涉及两个层面:
+ 1. `dp`的长度。通常是:`条件数组长度加1`或`条件数组长度`。
+ 2. `dp[i]`或`dp[i][j]`的值。`dp[0]`或`dp[0][0]`有时需要特殊处理。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
+ - “递推公式”是“动态规划”算法的核心。但“递推公式”是隐晦的,想得到它,就需要制表,用数据启发自己。
+ - 如果原示例不够好,需要自己重新设计一个。
+ - 根据示例,填入`dp`网格数据,需要“按顺序”填,这是很重要的,因为它决定了代码的遍历顺序。
+ - 大多时候,从左到右,从上到下。但有时需要从右向左、由下而上、从中间向右(或左),如“回文串”问题。有时,还需要一行遍历两次,先正向,再反向。
+ - 当顺序决定对了,起点就决定好了,从起点出发,“按顺序”填写`dp`网格数据,这也是在模拟程序处理的过程。
+ - 在此过程中,您将获得写出“递推公式”的灵感。如果您已经能推导出公式,不需要填完网格。
+4. 根据`dp`网格数据,推导出**递推公式**。
+ - 有三个特别的位置需要注意: `dp[i - 1][j - 1]`、`dp[i - 1][j]`和`dp[i][j - 1]`,当前的 `dp[i][j]`往往取决于它们。
+ - 操作“两个位置可互换的数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
+5. 写出程序,并打印`dp`数组,不合预期就调整。
+ - 重点分析那些不合预期的数值。
+
+读完了上面的内容,是不是感觉“动态规划”也没有那么难了?试着解出这道题吧。🤗
+
+## “子序列问题”的模式
+
+- 由于要比较有两个可互换位置的数组(或字符串),我们使用**二维**数组作为`dp`。
+- `dp` 数组的遍历顺序是从上到下,然后从左到右。
+
+## 步骤
+
+1. 确定数组`dp`的每个值代表的**含义**。
+ - `dp[i][j]` 表示将 `word1` 的前 `i` 个字母转换为 `word2` 的前 `j` 个字母所需的**最小**操作次数。
+ - `dp[i][j]` 是一个整数。
+2. 初始化数组`dp`的值。
+ - 使用示例:
+
+ ```
+ 初始化后,dp 数组应为:
+ # r o s
+ # 0 1 2 3 # dp[0]
+ # h 1 0 0 0
+ # o 2 0 0 0
+ # r 3 0 0 0
+ # s 4 0 0 0
+ # e 5 0 0 0
+ ```
+ - `dp[i][0] = i`,因为`dp[i][0]`表示空字符串,操作次数就是需要删除的字符数。
+ - `dp[0][j] = j`,原因与上一行相同,只是角度相反:将`word2`转换为`word1`。
+
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
+
+ ```
+ 1. 将`h`转换为`ros`。
+ # r o s
+ # 0 1 2 3
+ # h 1 1 2 3 # dp[1]
+ ```
+ ```
+ 2. 将`ho`转换为`ros`。
+ # r o s
+ # 0 1 2 3
+ # h 1 1 2 3
+ # o 2 2 1 2
+ ```
+ ```
+ 3. 将`hor`转换为`ros`。
+ # r o s
+ # 0 1 2 3
+ # h 1 1 2 3
+ # o 2 2 1 2
+ # r 3 2 2 2
+ ```
+ ```
+ 4. 将`hors`转换为`ros`。
+ # r o s
+ # 0 1 2 3
+ # h 1 1 2 3
+ # o 2 2 1 2
+ # r 3 2 2 2
+ # s 4 3 3 2
+ ```
+ ```
+ 5. 将 `horse` 转换为 `ros`。
+ # r o s
+ # 0 1 2 3
+ # h 1 1 2 3
+ # o 2 2 1 2
+ # r 3 2 2 2
+ # s 4 3 3 2
+ # e 5 4 4 3 # dp[5]
+ ```
+4. 根据`dp`网格数据,推导出**递推公式**。
+
+ ```python
+ if word1[i - 1] == word2[j - 1]:
+ dp[i][j] = dp[i - 1][j - 1]
+ else:
+ dp[i][j] = min(
+ dp[i - 1][j - 1],
+ dp[i - 1][j],
+ dp[i][j - 1],
+ ) + 1
+ ```
+5. 写出程序,并打印`dp`数组,不合预期就调整。
+
+## 复杂度
+
+- 时间复杂度: `O(N * M)`.
+- 空间复杂度: `O(N * M)`.
## Java
+
```java
class Solution {
public int minDistance(String word1, String word2) {
@@ -158,7 +204,8 @@ class Solution {
```
## C#
-```c#
+
+```csharp
public class Solution
{
public int MinDistance(string word1, string word2)
@@ -192,6 +239,7 @@ public class Solution
```
## Python
+
```python
class Solution:
def minDistance(self, word1: str, word2: str) -> int:
@@ -212,6 +260,7 @@ class Solution:
```
## C++
+
```cpp
class Solution {
public:
@@ -240,6 +289,7 @@ public:
```
## JavaScript
+
```javascript
var minDistance = function (word1, word2) {
const dp = Array(word1.length + 1).fill().map(
@@ -263,6 +313,7 @@ var minDistance = function (word1, word2) {
```
## Go
+
```go
func minDistance(word1 string, word2 string) int {
dp := make([][]int, len(word1) + 1)
@@ -289,6 +340,7 @@ func minDistance(word1 string, word2 string) int {
```
## Ruby
+
```ruby
def min_distance(word1, word2)
dp = Array.new(word1.size + 1) do
@@ -316,12 +368,16 @@ def min_distance(word1, word2)
end
```
-## Rust
-```rust
-// Welcome to create a PR to complete the code of this language, thanks!
-```
-
## Other languages
-```
+
+```java
// Welcome to create a PR to complete the code of this language, thanks!
```
+
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
+本站敢称力扣题解最佳实践,终将省你大量刷题时间!
+
+原文链接:[72. 编辑距离 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/72-edit-distance).
+
+GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
+
diff --git a/zh/1-1000/797-all-paths-from-source-to-target.md b/zh/1-1000/797-all-paths-from-source-to-target.md
index 04aa1cf..dfd1723 100644
--- a/zh/1-1000/797-all-paths-from-source-to-target.md
+++ b/zh/1-1000/797-all-paths-from-source-to-target.md
@@ -1,321 +1,594 @@
-# 797. All Paths From Source to Target
-LeetCode link: [797. All Paths From Source to Target](https://leetcode.com/problems/all-paths-from-source-to-target/)
+# 797. 所有可能的路径 - LeetCode Python/Java/C++ 题解
-## LeetCode problem description
-Given a directed acyclic graph (**DAG**) of `n` nodes labeled from `0` to `n - 1`, find all possible paths from node `0` to node `n - 1` and return them in **any order**.
+访问原文链接:[797. 所有可能的路径 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/797-all-paths-from-source-to-target),体验更佳!
-The graph is given as follows: `graph[i]` is a list of all nodes you can visit from node `i` (i.e., there is a directed edge from node `i` to node `graph[i][j]`).
+力扣链接:[797. 所有可能的路径](https://leetcode.cn/problems/all-paths-from-source-to-target), 难度等级:**中等**。
+
+## LeetCode “797. 所有可能的路径”问题描述
+
+给你一个有 `n` 个节点的 **有向无环图(DAG)**,请你找出所有从节点 `0` 到节点 `n-1` 的路径并输出(**不要求按特定顺序**)
+
+`graph[i]` 是一个从节点 `i` 可以访问的所有节点的列表(即从节点 `i` 到节点 `graph[i][j]` 存在一条有向边)。
+
+### [示例 1]
-### Example 1

-```
-Input: graph = [[1,2],[3],[3],[]]
-Output: [[0,1,3],[0,2,3]]
-Explanation: There are two paths: 0 -> 1 -> 3 and 0 -> 2 -> 3.
-```
-### Example 2
+**输入**: `graph = [[1,2],[3],[3],[]]`
+
+**输出**: `[[0,1,3],[0,2,3]]`
+
+**解释**: `有两条路径 0 -> 1 -> 3 和 0 -> 2 -> 3`
+
+### [示例 2]
+

-```
-Input: graph = [[4,3,1],[3,2,4],[3],[4],[]]
-Output: [[0,4],[0,3,4],[0,1,3,4],[0,1,2,3,4],[0,1,4]]
-```
-### Constraints
+**输入**: `graph = [[4,3,1],[3,2,4],[3],[4],[]]`
+
+**输出**: `[[0,4],[0,3,4],[0,1,3,4],[0,1,2,3,4],[0,1,4]]`
+
+### [约束]
+
- `n == graph.length`
- `2 <= n <= 15`
- `0 <= graph[i][j] < n`
-- `graph[i][j] != i` (i.e., there will be no self-loops).
-- All the elements of `graph[i]` are **unique**.
-- The input graph is **guaranteed** to be a **DAG**.
+- `graph[i][j] != i`(即不存在自环)
+- `graph[i]` 中的所有元素 **互不相同**
+- 保证输入为 **有向无环图(DAG)**
+
+## 思路 1
+
+
+
+## “深度优先搜索”的模式
+
+深度优先搜索(DFS)是一种经典的图遍历算法,其核心特点是**“尽可能深”**地探索图的分支。DFS 从起始顶点出发,沿着一条路径不断深入,直到到达没有未访问邻接点的顶点,然后回溯到最近的分叉点继续探索。这一过程通过**递归**或**显式栈(迭代法)**实现,形成“后进先出”的搜索顺序,因此 DFS 在非加权图中能快速找到离起点较远的深层节点。
+
+**与 BFS 的对比**:
+
+1. **搜索顺序**:DFS 优先探索深度方向,而广度优先搜索(BFS)按层逐层扩展,形成“先进先出”的队列结构。
+2. **适用场景**:DFS 更适合强连通分量或回溯类问题(如迷宫所有路径),而 BFS 擅长最短路径(未加权图)或邻近节点探索(如社交网络好友推荐)。
+
+**DFS 的独特性**:
+
+- **不完全性**:若图无限深或存在环路(未标记已访问),DFS 可能无法终止,而 BFS 总能找到最短路径(未加权图)。
+- **“一支笔走到底”** 的搜索风格,使其在回溯剪枝或记录路径时更具灵活性,但也可能错过近邻最优解。
+
-# Intuition
-This problem can be solved using **Depth-First Search of a Graph**.
+总之,DFS 以深度优先的策略揭示图的纵向结构,其回溯特性与栈的天然结合,使其在路径记录和状态空间探索中表现突出,但需注意处理环路和最优解缺失的局限性。
-# Approach
-1. From node `0`, visit all of its neighbors `graph[node]` in an iteration.
-2. In the iteration, recursively call the `dfs` function to visit all the paths.
-3. Use an array `path` to save the path (node itself inclusive).
-4. Around the `dfs()` call code are the `path.push(node)` (use `node`) and `path.pop()` (undo use `node`).
-5. Use an array `paths` to save the results.
+## 步骤
-## Complexity
-* Time: `O(2**n)`.
-* Space: `O(n)`.
+1. 初始化一个空列表 `paths`,用于存储所有找到的有效路径。
+2. 初始化一个堆栈来管理 DFS 遍历。堆栈中的每个元素将存储一个 pair(或元组),其中包含当前 `node` 和到达该节点所采用的 `path`。
+3. 将起始状态加入到堆栈:初始节点 `0` 和一个空的路径列表(例如 `(0, [])`)。
+4. 当堆栈不为空时:
+ - 从堆栈中弹出顶部元素,检索当前 `node` 及其关联的 `path`。
+ - 通过将当前 `node` 附加到从堆栈中弹出的 `path` 来创建一个 `currentPath` 数组,它表示通往当前节点并包含当前节点的路径。
+ - 检查当前 `node` 是否为目标节点(`n - 1`,其中 `n` 是节点总数)。
+ - 如果它是目标节点,则将 `currentPath` 添加到 `paths` 数组中,因为已经找到了从源节点到目标节点的完整路径。
+ - 如果不是目标节点,则遍历当前 `node` 可访问的所有 `neighbor` 节点(即遍历 `graph[node]`)。
+ - 对于每个 `neighbor`,将一个新的 pair(`neighbor` 节点和 `currentPath`)加入到堆栈中。这为遍历探索从邻居节点延伸的路径做好准备。
+5. 循环结束后(堆栈为空),返回 `paths` 数组,其中包含从节点 `0` 到节点 `n - 1` 的所有已发现路径。
+
+## 复杂度
+
+- 时间复杂度: `Too complex`.
+- 空间复杂度: `Too complex`.
## Python
-### Solution 1: New array as 'path' parameter
+
```python
class Solution:
- def __init__(self):
- self.paths = []
- self.graph = None
-
def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:
- self.graph = graph
+ paths = []
+ stack = [(0, [])]
- self.dfs(0, [0])
+ while stack:
+ node, path = stack.pop()
- return self.paths
-
- def dfs(self, node, path):
- if node == len(self.graph) - 1:
- self.paths.append(path.copy())
- return
+ if node == len(graph) - 1:
+ paths.append(path + [node])
+ continue
+
+ for target_node in graph[node]:
+ stack.append((target_node, path + [node]))
+
+ return paths
+```
+
+## Java
+
+```java
+class Solution {
+ public List> allPathsSourceTarget(int[][] graph) {
+ List> paths = new ArrayList<>();
+ // Each element in the stack is a pair: (current_node, current_path)
+ Stack>> stack = new Stack<>();
+ List initialPath = new ArrayList<>();
+ stack.push(new Pair<>(0, initialPath));
+
+ int targetNode = graph.length - 1;
+
+ while (!stack.isEmpty()) {
+ var current = stack.pop();
+ int node = current.getKey();
+ var path = current.getValue();
+
+ var nextPath = new ArrayList<>(path);
+ nextPath.add(node);
+
+ if (node == targetNode) {
+ paths.add(nextPath);
+ continue;
+ }
+
+ for (int neighbor : graph[node]) {
+ stack.push(new Pair<>(neighbor, nextPath));
+ }
+ }
+
+ return paths;
+ }
+}
+
+```
+
+## C++
+
+```cpp
+class Solution {
+public:
+ vector> allPathsSourceTarget(vector>& graph) {
+ vector> paths;
+ // Stack stores pairs of (current_node, current_path)
+ stack>> s;
+ s.push({0, {}}); // Start at node 0 with an empty path initially
+
+ int targetNode = graph.size() - 1;
+
+ while (!s.empty()) {
+ auto node_path = s.top();
+ s.pop();
+ int node = node_path.first;
+ vector path = node_path.second;
+
+ // Add the current node to the path
+ path.push_back(node);
+
+ if (node == targetNode) {
+ paths.push_back(path); // Found a path to the target
+ continue;
+ }
+
+ // Explore neighbors
+ for (int neighbor : graph[node]) {
+ s.push({neighbor, path});
+ }
+ }
+
+ return paths;
+ }
+};
+```
+
+## JavaScript
+
+```javascript
+/**
+ * @param {number[][]} graph
+ * @return {number[][]}
+ */
+var allPathsSourceTarget = function(graph) {
+ const paths = [];
+ // Stack stores arrays: [current_node, current_path]
+ const stack = [[0, []]]; // Start at node 0 with an empty path
+ const targetNode = graph.length - 1;
+
+ while (stack.length > 0) {
+ const [node, path] = stack.pop();
+
+ // Create the new path by appending the current node
+ const currentPath = [...path, node];
+
+ if (node === targetNode) {
+ paths.push(currentPath); // Found a path
+ continue;
+ }
+
+ // Explore neighbors
+ for (const neighbor of graph[node]) {
+ stack.push([neighbor, currentPath]); // Push neighbor and the path so far
+ }
+ }
+
+ return paths;
+};
+
+```
+
+## C#
+
+```csharp
+public class Solution {
+ public IList> AllPathsSourceTarget(int[][] graph)
+ {
+ var paths = new List>();
+ // Stack stores tuples: (current_node, current_path)
+ var stack = new Stack<(int node, List path)>();
+ stack.Push((0, new List())); // Start at node 0
+
+ int targetNode = graph.Length - 1;
+
+ while (stack.Count > 0)
+ {
+ var (node, path) = stack.Pop();
+
+ var currentPath = new List(path);
+ currentPath.Add(node);
+
+ if (node == targetNode)
+ {
+ paths.Add(currentPath); // Found a path
+ continue;
+ }
+
+ // Explore neighbors
+ foreach (int neighbor in graph[node])
+ {
+ stack.Push((neighbor, currentPath)); // Push neighbor and the path so far
+ }
+ }
+
+ return paths;
+ }
+}
+```
+
+## Go
+
+```go
+type StackItem struct {
+ Node int
+ Path []int
+}
+
+func allPathsSourceTarget(graph [][]int) [][]int {
+ var paths [][]int
+ stack := []StackItem{{Node: 0, Path: []int{}}} // Start at node 0
+
+ targetNode := len(graph) - 1
+
+ for len(stack) > 0 {
+ currentItem := stack[len(stack) - 1] // Pop from stack
+ stack = stack[:len(stack) - 1]
+
+ node := currentItem.Node
+ path := currentItem.Path
- for target_node in self.graph[node]:
- self.dfs(target_node, path + [target_node])
+ newPath := append([]int(nil), path...)
+ newPath = append(newPath, node)
+
+ if node == targetNode {
+ paths = append(paths, newPath) // Found a path
+ continue
+ }
+
+ for _, neighbor := range graph[node] {
+ stack = append(stack, StackItem{Node: neighbor, Path: newPath})
+ }
+ }
+
+ return paths
+}
```
-### Solution 2: More efficient by reusing one array (recommended)
+## Ruby
+
+```ruby
+# @param {Integer[][]} graph
+# @return {Integer[][]}
+def all_paths_source_target(graph)
+ paths = []
+ # Stack stores arrays: [current_node, current_path]
+ stack = [[0, []]] # Start at node 0 with an empty path
+ target_node = graph.length - 1
+
+ while !stack.empty?
+ node, path = stack.pop
+
+ # Create the new path by appending the current node
+ current_path = path + [node]
+
+ if node == target_node
+ paths << current_path # Found a path
+ next
+ end
+
+ # Explore neighbors
+ graph[node].each do |neighbor|
+ stack.push([neighbor, current_path])
+ end
+ end
+
+ paths
+end
+```
+
+## Other languages
+
+```java
+// Welcome to create a PR to complete the code of this language, thanks!
+```
+
+## 思路 2
+
+
+
+## “深度优先搜索”的模式
+
+深度优先搜索(DFS)是一种经典的图遍历算法,其核心特点是**“尽可能深”**地探索图的分支。DFS 从起始顶点出发,沿着一条路径不断深入,直到到达没有未访问邻接点的顶点,然后回溯到最近的分叉点继续探索。这一过程通过**递归**或**显式栈(迭代法)**实现,形成“后进先出”的搜索顺序,因此 DFS 在非加权图中能快速找到离起点较远的深层节点。
+
+**与 BFS 的对比**:
+
+1. **搜索顺序**:DFS 优先探索深度方向,而广度优先搜索(BFS)按层逐层扩展,形成“先进先出”的队列结构。
+2. **适用场景**:DFS 更适合强连通分量或回溯类问题(如迷宫所有路径),而 BFS 擅长最短路径(未加权图)或邻近节点探索(如社交网络好友推荐)。
+
+**DFS 的独特性**:
+
+- **不完全性**:若图无限深或存在环路(未标记已访问),DFS 可能无法终止,而 BFS 总能找到最短路径(未加权图)。
+- **“一支笔走到底”** 的搜索风格,使其在回溯剪枝或记录路径时更具灵活性,但也可能错过近邻最优解。
+
+
+总之,DFS 以深度优先的策略揭示图的纵向结构,其回溯特性与栈的天然结合,使其在路径记录和状态空间探索中表现突出,但需注意处理环路和最优解缺失的局限性。
+
+## “递归”的模式
+
+递归(Recursion)是计算机科学和数学中的一个重要概念,指的是 一个函数在其定义中 **直接或间接调用自身** 的方法。
+
+### 递归的核心思想
+
+- **自我调用**:函数在执行过程中调用自身。
+- **基线情况**:相当于终止条件。到达基线情况后,就可以返回结果了,不需要再递归调用,防止无限循环。
+- **递归步骤**:问题逐步向“基线情况”靠近的步骤。
+
+## 复杂度
+
+- 时间复杂度: `Too complex`.
+- 空间复杂度: `Too complex`.
+
+## Python
+
```python
class Solution:
- def __init__(self):
- self.paths = []
- self.path = [0]
- self.graph = None
-
def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:
+ self.paths = []
self.graph = graph
+ self.target = len(graph) - 1
- self.dfs(0)
+ self.dfs(0, []) # Start DFS from node 0 with an empty initial path
return self.paths
- def dfs(self, node):
- if node == len(self.graph) - 1:
- self.paths.append(self.path.copy())
- return
-
- for target_node in self.graph[node]:
- self.path.append(target_node)
+ def dfs(self, node, path):
+ current_path = path + [node]
- self.dfs(target_node)
+ if node == self.target: # Base case
+ self.paths.append(current_path)
+ return
- self.path.pop()
+ for neighbor in self.graph[node]: # Recursive step: Explore neighbors
+ self.dfs(neighbor, current_path)
```
## Java
+
```java
class Solution {
- List> paths = new ArrayList<>();
- List path = new ArrayList<>();
- int[][] graph;
+ private List> paths;
+ private int[][] graph;
+ private int targetNode;
public List> allPathsSourceTarget(int[][] graph) {
+ this.paths = new ArrayList<>();
this.graph = graph;
- path.add(0);
+ this.targetNode = graph.length - 1;
- dfs(0);
+ List initialPath = new ArrayList<>();
+ dfs(0, initialPath); // Start DFS from node 0 with an empty initial path
return paths;
}
- void dfs(int node) {
- if (node == graph.length - 1) {
- paths.add(new ArrayList<>(path));
+ private void dfs(int node, List currentPath) {
+ List newPath = new ArrayList<>(currentPath);
+ newPath.add(node);
+
+ if (node == targetNode) { // Base case
+ paths.add(newPath);
return;
}
- for (int targetNode : graph[node]) {
- path.add(targetNode);
-
- dfs(targetNode);
-
- path.removeLast();
+ for (int neighbor : graph[node]) { // Recursive step: Explore neighbors
+ dfs(neighbor, newPath);
}
}
}
```
## C++
+
```cpp
class Solution {
public:
vector> allPathsSourceTarget(vector>& graph) {
- graph_ = graph;
- path_.push_back(0);
+ _graph = graph;
- dfs(0);
+ vector initial_path; // Empty initial path
+ dfs(0, initial_path); // Start DFS from node 0
- return paths_;
+ return _paths;
}
private:
- vector> paths_;
- vector path_;
- vector> graph_;
+ vector> _paths;
+ vector> _graph;
- void dfs(int node) {
- if (node == graph_.size() - 1) {
- paths_.push_back(path_);
+ void dfs(int node, vector current_path) {
+ current_path.push_back(node);
+
+ if (node == _graph.size() - 1) { // Base case
+ _paths.push_back(current_path);
return;
}
- for (int target_node : graph_[node]) {
- path_.push_back(target_node);
-
- dfs(target_node);
-
- path_.pop_back();
+ for (int neighbor : _graph[node]) { // Recursive step: Explore neighbors
+ dfs(neighbor, current_path);
}
}
};
```
## JavaScript
+
```javascript
let paths
-let path
let graph
var allPathsSourceTarget = function (graph_) {
- graph = graph_
paths = []
- path = [0]
+ graph = graph_
- dfs(0)
+ dfs(0, [])
return paths
-};
+}
+
+function dfs(node, currentPath) {
+ const newPath = [...currentPath, node]
-function dfs(node) {
- if (node === graph.length - 1) {
- paths.push([...path])
+ if (node === graph.length - 1) { // Base case
+ paths.push(newPath)
return
}
- for (const targetNode of graph[node]) {
- path.push(targetNode)
-
- dfs(targetNode)
-
- path.pop()
+ for (const neighbor of graph[node]) { // Recursive step: Explore neighbors
+ dfs(neighbor, newPath)
}
}
+
```
## C#
-```c#
+
+```csharp
public class Solution
{
- IList> paths = new List>();
- IList path = new List();
- int[][] graph;
+ private IList> paths;
+ private int[][] graph;
+ private int targetNode;
public IList> AllPathsSourceTarget(int[][] graph)
{
+ this.paths = new List>();
this.graph = graph;
- path.Add(0);
+ this.targetNode = graph.Length - 1;
- dfs(0);
+ Dfs(0, new List());
return paths;
}
- void dfs(int node)
+ private void Dfs(int node, List currentPath)
{
- if (node == graph.Length - 1)
+ var newPath = new List(currentPath);
+ newPath.Add(node);
+
+ if (node == targetNode) // Base case
{
- paths.Add(path.ToList());
+ paths.Add(newPath);
return;
}
- foreach (int targetNode in graph[node])
+ foreach (int neighbor in graph[node]) // Recursive step: Explore neighbors
{
- path.Add(targetNode);
-
- dfs(targetNode);
-
- path.RemoveAt(path.Count - 1);
+ Dfs(neighbor, newPath);
}
}
}
```
## Go
+
```go
var (
paths [][]int
- path []int
graph [][]int
+ targetNode int
)
func allPathsSourceTarget(graph_ [][]int) [][]int {
+ paths = [][]int{}
graph = graph_
- paths = nil
- path = []int{0}
+ targetNode = len(graph) - 1
- dfs(0)
+ dfs(0, []int{})
return paths
}
-func dfs(node int) {
- if (node == len(graph) - 1) {
- paths = append(paths, slices.Clone(path))
+func dfs(node int, currentPath []int) {
+ newPath := append([]int(nil), currentPath...)
+ newPath = append(newPath, node)
+
+ if node == targetNode { // Base case
+ paths = append(paths, newPath)
return
}
- for _, targetNode := range graph[node] {
- path = append(path, targetNode)
-
- dfs(targetNode)
-
- path = path[:len(path) - 1]
+ for _, neighbor := range graph[node] { // Recursive step: Explore neighbors
+ dfs(neighbor, newPath)
}
}
```
## Ruby
+
```ruby
def all_paths_source_target(graph)
- @graph = graph
@paths = []
- @path = [0]
+ @graph = graph
- dfs(0)
+ dfs(0, [])
@paths
end
-def dfs(node)
- if node == @graph.size - 1
- @paths.append(@path.clone)
+def dfs(node, current_path)
+ new_path = current_path + [node]
+
+ if node == @graph.size - 1 # Base case
+ @paths << new_path
return
end
- @graph[node].each do |target_node|
- @path << target_node
-
- dfs(target_node)
-
- @path.pop
+ @graph[node].each do |neighbor| # Recursive step: Explore neighbors
+ dfs(neighbor, new_path)
end
end
```
-## C
-```c
-// Welcome to create a PR to complete the code of this language, thanks!
-```
+## Other languages
-## Kotlin
-```kotlin
+```java
// Welcome to create a PR to complete the code of this language, thanks!
```
-## Swift
-```swift
-// Welcome to create a PR to complete the code of this language, thanks!
-```
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
+本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-## Rust
-```rust
-// Welcome to create a PR to complete the code of this language, thanks!
-```
+原文链接:[797. 所有可能的路径 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/797-all-paths-from-source-to-target).
+
+GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
-## Other languages
-```
-// Welcome to create a PR to complete the code of this language, thanks!
-```
diff --git a/zh/1-1000/833-find-and-replace-in-string.md b/zh/1-1000/833-find-and-replace-in-string.md
index f795655..70de881 100644
--- a/zh/1-1000/833-find-and-replace-in-string.md
+++ b/zh/1-1000/833-find-and-replace-in-string.md
@@ -1,10 +1,10 @@
-# 833. 字符串中的查找与替换 - 力扣题解最佳实践
+# 833. 字符串中的查找与替换 - LeetCode Python/Java/C++ 题解
-访问原文链接:[833. 字符串中的查找与替换 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/833-find-and-replace-in-string),体验更佳!
+访问原文链接:[833. 字符串中的查找与替换 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/833-find-and-replace-in-string),体验更佳!
-力扣链接:[833. 字符串中的查找与替换](https://leetcode.cn/problems/find-and-replace-in-string), 难度:**中等**。
+力扣链接:[833. 字符串中的查找与替换](https://leetcode.cn/problems/find-and-replace-in-string), 难度等级:**中等**。
-## 力扣“833. 字符串中的查找与替换”问题描述
+## LeetCode “833. 字符串中的查找与替换”问题描述
你会得到一个字符串 `s` (索引从 0 开始),你必须对它执行 `k` 个替换操作。替换操作以三个长度均为 `k` 的并行数组给出:`indices`, `sources`, `targets`。
@@ -105,10 +105,10 @@ class Solution:
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[833. 字符串中的查找与替换 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/833-find-and-replace-in-string).
+原文链接:[833. 字符串中的查找与替换 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/833-find-and-replace-in-string).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1-1000/977-squares-of-a-sorted-array.md b/zh/1-1000/977-squares-of-a-sorted-array.md
index 7e7468c..f8cdfbf 100644
--- a/zh/1-1000/977-squares-of-a-sorted-array.md
+++ b/zh/1-1000/977-squares-of-a-sorted-array.md
@@ -1,10 +1,10 @@
-# 977. 有序数组的平方 - 力扣题解最佳实践
+# 977. 有序数组的平方 - LeetCode Python/Java/C++ 题解
-访问原文链接:[977. 有序数组的平方 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/977-squares-of-a-sorted-array),体验更佳!
+访问原文链接:[977. 有序数组的平方 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/977-squares-of-a-sorted-array),体验更佳!
-力扣链接:[977. 有序数组的平方](https://leetcode.cn/problems/squares-of-a-sorted-array), 难度:**简单**。
+力扣链接:[977. 有序数组的平方](https://leetcode.cn/problems/squares-of-a-sorted-array), 难度等级:**简单**。
-## 力扣“977. 有序数组的平方”问题描述
+## LeetCode “977. 有序数组的平方”问题描述
给你一个按 **非递减顺序** 排序的整数数组 `nums`,返回 **每个数字的平方** 组成的新数组,要求也按 **非递减顺序** 排序。
@@ -346,10 +346,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[977. 有序数组的平方 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/977-squares-of-a-sorted-array).
+原文链接:[977. 有序数组的平方 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/977-squares-of-a-sorted-array).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/1001-2000/1049-last-stone-weight-ii.md b/zh/1001-2000/1049-last-stone-weight-ii.md
index 66e2b10..e7644fe 100644
--- a/zh/1001-2000/1049-last-stone-weight-ii.md
+++ b/zh/1001-2000/1049-last-stone-weight-ii.md
@@ -1,10 +1,10 @@
-# 1049. 最后一块石头的重量 II - 力扣题解最佳实践
+# 1049. 最后一块石头的重量 II - LeetCode Python/Java/C++ 题解
-访问原文链接:[1049. 最后一块石头的重量 II - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/1049-last-stone-weight-ii),体验更佳!
+访问原文链接:[1049. 最后一块石头的重量 II - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/1049-last-stone-weight-ii),体验更佳!
-力扣链接:[1049. 最后一块石头的重量 II](https://leetcode.cn/problems/last-stone-weight-ii), 难度:**中等**。
+力扣链接:[1049. 最后一块石头的重量 II](https://leetcode.cn/problems/last-stone-weight-ii), 难度等级:**中等**。
-## 力扣“1049. 最后一块石头的重量 II”问题描述
+## LeetCode “1049. 最后一块石头的重量 II”问题描述
有一堆石头,用整数数组 `stones` 表示。其中 `stones[i]` 表示第 `i` 块石头的重量。
@@ -68,32 +68,32 @@
#### “动态规划”分为五步
-1. 确定数组`dp`的每个值代表的含义。
+1. 确定数组`dp`的每个值代表的**含义**。
2. 初始化数组`dp`的值。
-3. 根据一个示例,“按顺序”填入`dp`网格数据。
-4. 根据`dp`网格数据,推导出“递推公式”。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
+4. 根据`dp`网格数据,推导出**递推公式**。
5. 写出程序,并打印`dp`数组,不合预期就调整。
#### 细说这五步
-1. 确定数组`dp`的每个值代表的含义。
- - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个对等数组”,为了理解方便,还是使用“二维数组”。
+1. 确定数组`dp`的每个值代表的**含义**。
+ - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个位置可互换的数组”,为了理解方便,还是使用“二维数组”。
- 尝试使用问题所求的`返回值`的含义作为 `dp[i]`(一维)或`dp[i][j]`(二维)的含义,约60%的概率能行。如果不行,再尝试其他含义。
- 设计上尽量考虑保存更丰富的信息,重复信息只在某个`dp[i]`中保存一次就够了。
- 使用简化的含义。如果用`布尔值`可以解决问题,就不要用`数值`。
2. 初始化数组`dp`的值。`dp`的值涉及两个层面:
1. `dp`的长度。通常是:`条件数组长度加1`或`条件数组长度`。
2. `dp[i]`或`dp[i][j]`的值。`dp[0]`或`dp[0][0]`有时需要特殊处理。
-3. 根据一个示例,“按顺序”填入`dp`网格数据。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
- “递推公式”是“动态规划”算法的核心。但“递推公式”是隐晦的,想得到它,就需要制表,用数据启发自己。
- 如果原示例不够好,需要自己重新设计一个。
- 根据示例,填入`dp`网格数据,需要“按顺序”填,这是很重要的,因为它决定了代码的遍历顺序。
- 大多时候,从左到右,从上到下。但有时需要从右向左、由下而上、从中间向右(或左),如“回文串”问题。有时,还需要一行遍历两次,先正向,再反向。
- 当顺序决定对了,起点就决定好了,从起点出发,“按顺序”填写`dp`网格数据,这也是在模拟程序处理的过程。
- 在此过程中,您将获得写出“递推公式”的灵感。如果您已经能推导出公式,不需要填完网格。
-4. 根据`dp`网格数据,推导出“递推公式”。
+4. 根据`dp`网格数据,推导出**递推公式**。
- 有三个特别的位置需要注意: `dp[i - 1][j - 1]`、`dp[i - 1][j]`和`dp[i][j - 1]`,当前的 `dp[i][j]`往往取决于它们。
- - 操作“两个对等数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
+ - 操作“两个位置可互换的数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
5. 写出程序,并打印`dp`数组,不合预期就调整。
- 重点分析那些不合预期的数值。
@@ -589,10 +589,10 @@ end
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[1049. 最后一块石头的重量 II - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/1049-last-stone-weight-ii).
+原文链接:[1049. 最后一块石头的重量 II - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/1049-last-stone-weight-ii).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/3001-4000/3478-choose-k-elements-with-maximum-sum.md b/zh/3001-4000/3478-choose-k-elements-with-maximum-sum.md
index 43b2173..b7bdbbc 100644
--- a/zh/3001-4000/3478-choose-k-elements-with-maximum-sum.md
+++ b/zh/3001-4000/3478-choose-k-elements-with-maximum-sum.md
@@ -1,10 +1,10 @@
-# 3478. 选出和最大的 K 个元素 - 力扣题解最佳实践
+# 3478. 选出和最大的 K 个元素 - LeetCode Python/Java/C++ 题解
-访问原文链接:[3478. 选出和最大的 K 个元素 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/3478-choose-k-elements-with-maximum-sum),体验更佳!
+访问原文链接:[3478. 选出和最大的 K 个元素 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/3478-choose-k-elements-with-maximum-sum),体验更佳!
-力扣链接:[3478. 选出和最大的 K 个元素](https://leetcode.cn/problems/choose-k-elements-with-maximum-sum), 难度:**中等**。
+力扣链接:[3478. 选出和最大的 K 个元素](https://leetcode.cn/problems/choose-k-elements-with-maximum-sum), 难度等级:**中等**。
-## 力扣“3478. 选出和最大的 K 个元素”问题描述
+## LeetCode “3478. 选出和最大的 K 个元素”问题描述
给你两个整数数组,`nums1` 和 `nums2`,长度均为 `n`,以及一个正整数 `k` 。
@@ -131,10 +131,10 @@ class Solution:
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[3478. 选出和最大的 K 个元素 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/3478-choose-k-elements-with-maximum-sum).
+原文链接:[3478. 选出和最大的 K 个元素 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/3478-choose-k-elements-with-maximum-sum).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
diff --git a/zh/3001-4000/3494-find-the-minimum-amount-of-time-to-brew-potions.md b/zh/3001-4000/3494-find-the-minimum-amount-of-time-to-brew-potions.md
index 087b66b..28b1842 100644
--- a/zh/3001-4000/3494-find-the-minimum-amount-of-time-to-brew-potions.md
+++ b/zh/3001-4000/3494-find-the-minimum-amount-of-time-to-brew-potions.md
@@ -1,10 +1,10 @@
-# 3494. 酿造药水需要的最少总时间 - 力扣题解最佳实践
+# 3494. 酿造药水需要的最少总时间 - LeetCode Python/Java/C++ 题解
-访问原文链接:[3494. 酿造药水需要的最少总时间 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/3494-find-the-minimum-amount-of-time-to-brew-potions),体验更佳!
+访问原文链接:[3494. 酿造药水需要的最少总时间 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/3494-find-the-minimum-amount-of-time-to-brew-potions),体验更佳!
-力扣链接:[3494. 酿造药水需要的最少总时间](https://leetcode.cn/problems/find-the-minimum-amount-of-time-to-brew-potions), 难度:**中等**。
+力扣链接:[3494. 酿造药水需要的最少总时间](https://leetcode.cn/problems/find-the-minimum-amount-of-time-to-brew-potions), 难度等级:**中等**。
-## 力扣“3494. 酿造药水需要的最少总时间”问题描述
+## LeetCode “3494. 酿造药水需要的最少总时间”问题描述
给你两个长度分别为 `n` 和 `m` 的整数数组 `skill` 和 `mana` 。
@@ -131,32 +131,32 @@
#### “动态规划”分为五步
-1. 确定数组`dp`的每个值代表的含义。
+1. 确定数组`dp`的每个值代表的**含义**。
2. 初始化数组`dp`的值。
-3. 根据一个示例,“按顺序”填入`dp`网格数据。
-4. 根据`dp`网格数据,推导出“递推公式”。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
+4. 根据`dp`网格数据,推导出**递推公式**。
5. 写出程序,并打印`dp`数组,不合预期就调整。
#### 细说这五步
-1. 确定数组`dp`的每个值代表的含义。
- - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个对等数组”,为了理解方便,还是使用“二维数组”。
+1. 确定数组`dp`的每个值代表的**含义**。
+ - 先确定`dp`是一维数组还是二维数组。“一维滚动数组”意味着每次迭代时都会覆盖数组的值。大多时候,用“一维滚动数组”代替“二维数组”可以简化代码;但有些题目,比如要操作“两个位置可互换的数组”,为了理解方便,还是使用“二维数组”。
- 尝试使用问题所求的`返回值`的含义作为 `dp[i]`(一维)或`dp[i][j]`(二维)的含义,约60%的概率能行。如果不行,再尝试其他含义。
- 设计上尽量考虑保存更丰富的信息,重复信息只在某个`dp[i]`中保存一次就够了。
- 使用简化的含义。如果用`布尔值`可以解决问题,就不要用`数值`。
2. 初始化数组`dp`的值。`dp`的值涉及两个层面:
1. `dp`的长度。通常是:`条件数组长度加1`或`条件数组长度`。
2. `dp[i]`或`dp[i][j]`的值。`dp[0]`或`dp[0][0]`有时需要特殊处理。
-3. 根据一个示例,“按顺序”填入`dp`网格数据。
+3. 根据一个示例,**按顺序**填入`dp`网格数据。
- “递推公式”是“动态规划”算法的核心。但“递推公式”是隐晦的,想得到它,就需要制表,用数据启发自己。
- 如果原示例不够好,需要自己重新设计一个。
- 根据示例,填入`dp`网格数据,需要“按顺序”填,这是很重要的,因为它决定了代码的遍历顺序。
- 大多时候,从左到右,从上到下。但有时需要从右向左、由下而上、从中间向右(或左),如“回文串”问题。有时,还需要一行遍历两次,先正向,再反向。
- 当顺序决定对了,起点就决定好了,从起点出发,“按顺序”填写`dp`网格数据,这也是在模拟程序处理的过程。
- 在此过程中,您将获得写出“递推公式”的灵感。如果您已经能推导出公式,不需要填完网格。
-4. 根据`dp`网格数据,推导出“递推公式”。
+4. 根据`dp`网格数据,推导出**递推公式**。
- 有三个特别的位置需要注意: `dp[i - 1][j - 1]`、`dp[i - 1][j]`和`dp[i][j - 1]`,当前的 `dp[i][j]`往往取决于它们。
- - 操作“两个对等数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
+ - 操作“两个位置可互换的数组”时,因为对称性,我们可能需要同时使用`dp[i - 1][j]`和`dp[i][j - 1]`。
5. 写出程序,并打印`dp`数组,不合预期就调整。
- 重点分析那些不合预期的数值。
@@ -432,10 +432,10 @@ func minTime(skill []int, mana []int) int64 {
// Welcome to create a PR to complete the code of this language, thanks!
```
-亲爱的力扣人,为了您更好的刷题体验,请访问 [leetcoder.net](https://leetcoder.net/zh)。
+亲爱的力扣人,为了您更好的刷题体验,请访问 [LeetCodePython.com](https://leetcodepython.com/zh)。
本站敢称力扣题解最佳实践,终将省你大量刷题时间!
-原文链接:[3494. 酿造药水需要的最少总时间 - 力扣题解最佳实践](https://leetcoder.net/zh/leetcode/3494-find-the-minimum-amount-of-time-to-brew-potions).
+原文链接:[3494. 酿造药水需要的最少总时间 - LeetCode Python/Java/C++ 题解](https://leetcodepython.com/zh/leetcode/3494-find-the-minimum-amount-of-time-to-brew-potions).
GitHub 仓库: [f*ck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).