Skip to content

Commit dd24456

Browse files
committed
Perfected some code to use int to make it more readable.
1 parent 4d091ad commit dd24456

5 files changed

+10
-13
lines changed

README.md

-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
# A best practice for the LeetCode problems
22
There are more than 3300 questions on LeetCode. If you do it without any choice, **you won't have that much time**.
3-
43
**You often find that you can't do the questions you did last time.** This is because you haven't mastered the problem-solving patterns.
5-
64
When you use several common problem-solving patterns to solve problems, you find that your problem-solving ability has risen to a new level.
75

86
Here, I will provide you with **common problem-solving patterns** so that you don't waste time on questions that are not often tested in interviews.
97

108
I will also provide you with solutions for many common programming languages, such as **Python, C++, Java, JavaScript, C#, Go, Ruby**, etc.
11-
129
I have tried my best to write the most concise and efficient code, so I call it my best practice. If you have better solutions, welcome to create an issue or PR!
1310

1411
## How to use this repo?
1512
I have planned a learning route for you. You just need to do the questions in the order they are listed.
1613

1714
Generally speaking, the simple questions are placed at the front, and the dependencies between the questions are also considered reasonably.
18-
1915
After finishing one category of questions, you can study another category to improve your sense of achievement and learning speed.
2016

2117
# Brute Force

problems/0084-largest-rectangle-in-histogram.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class Solution {
105105
public:
106106
int largestRectangleArea(vector<int> heights) {
107107
heights.insert(heights.begin(), 0);
108-
heights.emplace_back(0);
108+
heights.push_back(0);
109109
auto max_area = 0;
110110
stack<int> index_stack;
111111

problems/0509-fibonacci-number.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,22 @@ class Solution:
162162
### Solution 1: Recursion
163163
```cpp
164164
class Solution {
165-
unordered_map<int, int> num_to_fib_num;
165+
private:
166+
unordered_map<int, int> num_to_fib_num_;
166167

167168
public:
168169
int fib(int n) {
169170
if (n <= 1) {
170171
return n;
171172
}
172173

173-
if (num_to_fib_num.contains(n)) {
174-
return num_to_fib_num[n];
174+
if (num_to_fib_num_.contains(n)) {
175+
return num_to_fib_num_[n];
175176
}
176177

177-
num_to_fib_num[n] = fib(n - 1) + fib(n - 2);
178+
num_to_fib_num_[n] = fib(n - 1) + fib(n - 2);
178179

179-
return num_to_fib_num[n];
180+
return num_to_fib_num_[n];
180181
}
181182
};
182183
```
@@ -229,7 +230,7 @@ public:
229230
### Solution 1: Recursion
230231
```java
231232
class Solution {
232-
Map<Integer, Integer> numToFibNum = new HashMap<Integer, Integer>();
233+
var numToFibNum = new HashMap<Integer, Integer>();
233234

234235
public int fib(int n) {
235236
if (n <= 1) {

problems/0518-coin-change-ii.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class Solution
6363
var dp = new int[amount + 1];
6464
dp[0] = 1;
6565

66-
foreach (var coin in coins)
66+
foreach (int coin in coins)
6767
{
6868
for (var j = coin; j < dp.Length; j++)
6969
{

problems/1049-last-stone-weight-ii.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public class Solution {
180180
var dp = new bool[sum / 2 + 1];
181181
dp[0] = true;
182182

183-
foreach (var stone in stones) {
183+
foreach (int stone in stones) {
184184
for (var j = dp.GetUpperBound(0); j >= stone; j--) {
185185
dp[j] = dp[j] || dp[j - stone];
186186
}

0 commit comments

Comments
 (0)