Skip to content

Commit 00a3c7b

Browse files
committed
feat: update solutions to lc problems
* No.0741.Cherry Pickup * No.0796.Rotate String * No.1463.Cherry Pickup II
1 parent 22de3eb commit 00a3c7b

File tree

11 files changed

+33
-57
lines changed

11 files changed

+33
-57
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
- [在排序数组中查找元素的第一个和最后一个位置](/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README.md) - 二分查找
3838
- [准时到达的列车最小时速](/solution/1800-1899/1870.Minimum%20Speed%20to%20Arrive%20on%20Time/README.md) - 二分查找
39+
- [找到需要补充粉笔的学生编号](/solution/1800-1899/1894.Find%20the%20Student%20that%20Will%20Replace%20the%20Chalk/README.md) - 二分查找
3940
- [可移除字符的最大数目](/solution/1800-1899/1898.Maximum%20Number%20of%20Removable%20Characters/README.md) - 二分查找
4041

4142
### 2. 搜索
@@ -65,6 +66,8 @@
6566
- [最小路径和](/solution/0000-0099/0064.Minimum%20Path%20Sum/README.md) - 线性 DP、数字三角形模型
6667
- [摘樱桃](/solution/0700-0799/0741.Cherry%20Pickup/README.md) - 线性 DP、数字三角形模型
6768
- [摘樱桃 II](/solution/1400-1499/1463.Cherry%20Pickup%20II/README.md) - 线性 DP、数字三角形模型
69+
- [最长递增子序列](/solution/0300-0399/0300.Longest%20Increasing%20Subsequence/README.md) - 线性 DP、最长上升子序列模型
70+
6871

6972
### 4. 高级数据结构
7073

README_EN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Complete solutions to [LeetCode](https://leetcode.com/problemset/all/), [LCOF](h
3535

3636
- [Find First and Last Position of Element in Sorted Array](/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README_EN.md) - Binary search
3737
- [Minimum Speed to Arrive on Time](/solution/1800-1899/1870.Minimum%20Speed%20to%20Arrive%20on%20Time/README_EN.md) - Binary search
38+
- [Find the Student that Will Replace the Chalk](/solution/1800-1899/1894.Find%20the%20Student%20that%20Will%20Replace%20the%20Chalk/README_EN.md) - Binary search
3839
- [Maximum Number of Removable Characters](/solution/1800-1899/1898.Maximum%20Number%20of%20Removable%20Characters/README_EN.md) - Binary search
3940

4041
#### 2. Search
@@ -64,6 +65,7 @@ Complete solutions to [LeetCode](https://leetcode.com/problemset/all/), [LCOF](h
6465
- [Minimum Path Sum](/solution/0000-0099/0064.Minimum%20Path%20Sum/README_EN.md) - Linear problem
6566
- [Cherry Pickup](/solution/0700-0799/0741.Cherry%20Pickup/README_EN.md) - Linear problem
6667
- [Cherry Pickup II](/solution/1400-1499/1463.Cherry%20Pickup%20II/README_EN.md) - Linear problem
68+
- [Longest Increasing Subsequence](/solution/0300-0399/0300.Longest%20Increasing%20Subsequence/README_EN.md) - Linear problem
6769

6870
### 4. Advanced Data Structures
6971

solution/0700-0799/0741.Cherry Pickup/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@
5252

5353
**方法一:动态规划**
5454

55-
线性 DP。
55+
线性 DP。题目中,玩家从 `(0, 0)``(N-1, N-1)` 后又重新返回到起始点 `(0, 0)`,我们可以视为玩家两次从 `(0, 0)` 出发到 `(N-1, N-1)`
56+
57+
定义 `dp[k][i1][i2]` 表示两次路径同时走了 k 步,并且第一次走到 `(i1, k-i1)`,第二次走到 `(i2, k-i2)` 的所有路径中,可获得的樱桃数量的最大值。
5658

5759
类似题型:方格取数、传纸条。
5860

solution/0700-0799/0796.Rotate String/README.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@
5252
```python
5353
class Solution:
5454
def rotateString(self, s: str, goal: str) -> bool:
55-
if len(s) != len(goal):
56-
return False
57-
return goal in s + s
55+
return len(s) == len(goal) and goal in s + s
5856
```
5957

6058
### **Java**
@@ -64,10 +62,7 @@ class Solution:
6462
```java
6563
class Solution {
6664
public boolean rotateString(String s, String goal) {
67-
if (s.length() != goal.length()) {
68-
return false;
69-
}
70-
return (s + s).contains(goal);
65+
return s.length() == goal.length() && (s + s).contains(goal);
7166
}
7267
}
7368
```
@@ -78,10 +73,7 @@ class Solution {
7873
class Solution {
7974
public:
8075
bool rotateString(string s, string goal) {
81-
if (s.size() != goal.size()) {
82-
return false;
83-
}
84-
return !!strstr((s + s).data(), goal.data());
76+
return s.size() == goal.size() && strstr((s + s).data(), goal.data());
8577
}
8678
};
8779
```
@@ -90,10 +82,7 @@ public:
9082
9183
```go
9284
func rotateString(s string, goal string) bool {
93-
if len(s) != len(goal) {
94-
return false
95-
}
96-
return strings.Contains(s+s, goal)
85+
return len(s) == len(goal) && strings.Contains(s+s, goal)
9786
}
9887
```
9988

solution/0700-0799/0796.Rotate String/README_EN.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,15 @@
3737
```python
3838
class Solution:
3939
def rotateString(self, s: str, goal: str) -> bool:
40-
if len(s) != len(goal):
41-
return False
42-
return goal in s + s
40+
return len(s) == len(goal) and goal in s + s
4341
```
4442

4543
### **Java**
4644

4745
```java
4846
class Solution {
4947
public boolean rotateString(String s, String goal) {
50-
if (s.length() != goal.length()) {
51-
return false;
52-
}
53-
return (s + s).contains(goal);
48+
return s.length() == goal.length() && (s + s).contains(goal);
5449
}
5550
}
5651
```
@@ -61,10 +56,7 @@ class Solution {
6156
class Solution {
6257
public:
6358
bool rotateString(string s, string goal) {
64-
if (s.size() != goal.size()) {
65-
return false;
66-
}
67-
return !!strstr((s + s).data(), goal.data());
59+
return s.size() == goal.size() && strstr((s + s).data(), goal.data());
6860
}
6961
};
7062
```
@@ -73,10 +65,7 @@ public:
7365
7466
```go
7567
func rotateString(s string, goal string) bool {
76-
if len(s) != len(goal) {
77-
return false
78-
}
79-
return strings.Contains(s+s, goal)
68+
return len(s) == len(goal) && strings.Contains(s+s, goal)
8069
}
8170
```
8271

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
class Solution {
2-
public:
3-
bool rotateString(string s, string goal) {
4-
if (s.size() != goal.size()) {
5-
return false;
6-
}
7-
return !!strstr((s + s).data(), goal.data());
8-
}
1+
class Solution {
2+
public:
3+
bool rotateString(string s, string goal) {
4+
return s.size() == goal.size() && strstr((s + s).data(), goal.data());
5+
}
96
};
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
func rotateString(s string, goal string) bool {
2-
if len(s) != len(goal) {
3-
return false
4-
}
5-
return strings.Contains(s+s, goal)
1+
func rotateString(s string, goal string) bool {
2+
return len(s) == len(goal) && strings.Contains(s+s, goal)
63
}
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
class Solution {
2-
public boolean rotateString(String s, String goal) {
3-
if (s.length() != goal.length()) {
4-
return false;
5-
}
6-
return (s + s).contains(goal);
7-
}
1+
class Solution {
2+
public boolean rotateString(String s, String goal) {
3+
return s.length() == goal.length() && (s + s).contains(goal);
4+
}
85
}
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
class Solution:
2-
def rotateString(self, s: str, goal: str) -> bool:
3-
if len(s) != len(goal):
4-
return False
5-
return goal in s + s
1+
class Solution:
2+
def rotateString(self, s: str, goal: str) -> bool:
3+
return len(s) == len(goal) and goal in s + s

solution/1400-1499/1463.Cherry Pickup II/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575

7676
**方法一:动态规划**
7777

78-
线性 DP。
78+
线性 DP。定义 `dp[i][j1][j2]` 表示两个机器人从起始点分别走到坐标 `(i, j1)`, `(i, j2)` 的所有路线中,可获得的樱桃数量的最大值。
7979

8080
<!-- tabs:start -->
8181

0 commit comments

Comments
 (0)