Skip to content

Commit 156f7a6

Browse files
committed
auto commit
1 parent 6027156 commit 156f7a6

15 files changed

+96
-68
lines changed

notes/10.1 斐波那契数列.md

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

33
## 题目链接
44

5-
[NowCoder](https://www.nowcoder.com/practice/c6c7742f5ba7442aada113136ddea0c3?tpId=13&tqId=11160&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
5+
[牛客网](https://www.nowcoder.com/practice/c6c7742f5ba7442aada113136ddea0c3?tpId=13&tqId=11160&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
66

77
## 题目描述
88

notes/10.2 矩形覆盖.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 题目链接
44

5-
[NowCoder](https://www.nowcoder.com/practice/72a5a919508a4251859fb2cfb987a0e6?tpId=13&tqId=11163&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
5+
[牛客网](https://www.nowcoder.com/practice/72a5a919508a4251859fb2cfb987a0e6?tpId=13&tqId=11163&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
66

77
## 题目描述
88

@@ -27,7 +27,7 @@
2727
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/508c6e52-9f93-44ed-b6b9-e69050e14807.jpg" width="370px"> </div><br>
2828

2929
```java
30-
public int RectCover(int n) {
30+
public int rectCover(int n) {
3131
if (n <= 2)
3232
return n;
3333
int pre2 = 1, pre1 = 2;

notes/10.3 跳台阶.md

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

33
## 题目链接
44

5-
[NowCoder](https://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4?tpId=13&tqId=11161&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
5+
[牛客网](https://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4?tpId=13&tqId=11161&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
66

77
## 题目描述
88

notes/10.4 变态跳台阶.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 题目链接
44

5-
[NowCoder](https://www.nowcoder.com/practice/22243d016f6b47f2a6928b4313c85387?tpId=13&tqId=11162&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
5+
[牛客网](https://www.nowcoder.com/practice/22243d016f6b47f2a6928b4313c85387?tpId=13&tqId=11162&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
66

77
## 题目描述
88

@@ -15,7 +15,7 @@
1515
### 动态规划
1616

1717
```java
18-
public int JumpFloorII(int target) {
18+
public int jumpFloorII(int target) {
1919
int[] dp = new int[target];
2020
Arrays.fill(dp, 1);
2121
for (int i = 1; i < target; i++)

notes/12. 矩阵中的路径.md

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 12. 矩阵中的路径
22

3-
[NowCoder](https://www.nowcoder.com/practice/c61c6999eecb4b8f88a98f66b273a3cc?tpId=13&tqId=11218&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
3+
[牛客网](https://www.nowcoder.com/practice/69fe7a584f0a445da1b6652978de5c38?tpId=13&tqId=11218&tab=answerKey&from=cyc_github)
44

55
## 题目描述
66

@@ -19,46 +19,60 @@
1919
本题的输入是数组而不是矩阵(二维数组),因此需要先将数组转换成矩阵。
2020

2121
```java
22-
private final static int[][] next = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};
23-
private int rows;
24-
private int cols;
25-
26-
public boolean hasPath(char[] array, int rows, int cols, char[] str) {
27-
if (rows == 0 || cols == 0) return false;
28-
this.rows = rows;
29-
this.cols = cols;
30-
boolean[][] marked = new boolean[rows][cols];
31-
char[][] matrix = buildMatrix(array);
32-
for (int i = 0; i < rows; i++)
33-
for (int j = 0; j < cols; j++)
34-
if (backtracking(matrix, str, marked, 0, i, j))
35-
return true;
22+
public class Solution {
23+
private final static int[][] next = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};
24+
private int rows;
25+
private int cols;
26+
27+
public boolean hasPath (String val, int rows, int cols, String path) {
28+
if (rows == 0 || cols == 0) return false;
29+
this.rows = rows;
30+
this.cols = cols;
31+
char[] array = val.toCharArray();
32+
char[][] matrix = buildMatrix(array);
33+
char[] pathList = path.toCharArray();
34+
boolean[][] marked = new boolean[rows][cols];
35+
for (int i = 0; i < rows; i++)
36+
for (int j = 0; j < cols; j++)
37+
if (backtracking(matrix, pathList, marked, 0, i, j))
38+
return true;
3639

37-
return false;
38-
}
40+
return false;
41+
}
3942

40-
private boolean backtracking(char[][] matrix, char[] str,
41-
boolean[][] marked, int pathLen, int r, int c) {
43+
private boolean backtracking(char[][] matrix, char[] pathList,
44+
boolean[][] marked, int pathLen, int r, int c) {
4245

43-
if (pathLen == str.length) return true;
44-
if (r < 0 || r >= rows || c < 0 || c >= cols
45-
|| matrix[r][c] != str[pathLen] || marked[r][c]) {
46+
if (pathLen == pathList.length) return true;
47+
if (r < 0 || r >= rows || c < 0 || c >= cols
48+
|| matrix[r][c] != pathList[pathLen] || marked[r][c]) {
4649

50+
return false;
51+
}
52+
marked[r][c] = true;
53+
for (int[] n : next)
54+
if (backtracking(matrix, pathList, marked, pathLen + 1, r + n[0], c + n[1]))
55+
return true;
56+
marked[r][c] = false;
4757
return false;
4858
}
49-
marked[r][c] = true;
50-
for (int[] n : next)
51-
if (backtracking(matrix, str, marked, pathLen + 1, r + n[0], c + n[1]))
52-
return true;
53-
marked[r][c] = false;
54-
return false;
55-
}
5659

57-
private char[][] buildMatrix(char[] array) {
58-
char[][] matrix = new char[rows][cols];
59-
for (int r = 0, idx = 0; r < rows; r++)
60-
for (int c = 0; c < cols; c++)
61-
matrix[r][c] = array[idx++];
62-
return matrix;
60+
private char[][] buildMatrix(char[] array) {
61+
char[][] matrix = new char[rows][cols];
62+
for (int r = 0, idx = 0; r < rows; r++)
63+
for (int c = 0; c < cols; c++)
64+
matrix[r][c] = array[idx++];
65+
return matrix;
66+
}
67+
68+
public static void main(String[] args) {
69+
Solution solution = new Solution();
70+
String val = "ABCESFCSADEE";
71+
int rows = 3;
72+
int cols = 4;
73+
String path = "ABCCED";
74+
boolean res = solution.hasPath(val, rows, cols, path);
75+
System.out.println(res);
76+
}
6377
}
6478
```

notes/13. 机器人的运动范围.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 13. 机器人的运动范围
22

3-
[NowCoder](https://www.nowcoder.com/practice/6e5207314b5241fb83f2329e89fdecc8?tpId=13&tqId=11219&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
3+
[牛客网](https://www.nowcoder.com/practice/6e5207314b5241fb83f2329e89fdecc8?tpId=13&tqId=11219&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
44

55
## 题目描述
66

notes/14. 剪绳子.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 题目链接
44

5-
[Leetcode](https://leetcode.com/problems/integer-break/description/)
5+
[牛客网](https://www.nowcoder.com/practice/57d85990ba5b440ab888fc72b0751bf8?tpId=13&tqId=33257&tab=answerKey&from=cyc_github)
66

77
## 题目描述
88

@@ -37,7 +37,7 @@ return 36 (10 = 3 + 3 + 4)
3737
继续拆成更大的绳子可以发现都比拆成 2 和 3 的效果更差,因此我们只考虑将绳子拆成 2 和 3,并且优先拆成 3,当拆到绳子长度 n 等于 4 时,也就是出现 3+1,此时只能拆成 2+2。
3838

3939
```java
40-
public int integerBreak(int n) {
40+
public int cutRope(int n) {
4141
if (n < 2)
4242
return 0;
4343
if (n == 2)
@@ -55,7 +55,7 @@ public int integerBreak(int n) {
5555
### 动态规划
5656

5757
```java
58-
public int integerBreak(int n) {
58+
public int cutRope(int n) {
5959
int[] dp = new int[n + 1];
6060
dp[1] = 1;
6161
for (int i = 2; i <= n; i++)

notes/18.2 删除链表中重复的结点.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 18.2 删除链表中重复的结点
22

3-
[NowCoder](https://www.nowcoder.com/practice/fc533c45b73a41b0b44ccba763f866ef?tpId=13&tqId=11209&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
3+
[牛客网](https://www.nowcoder.com/practice/fc533c45b73a41b0b44ccba763f866ef?tpId=13&tqId=11209&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
44

55
## 题目描述
66

notes/19. 正则表达式匹配.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 19. 正则表达式匹配
22

3-
[NowCoder](https://www.nowcoder.com/practice/45327ae22b7b413ea21df13ee7d6429c?tpId=13&tqId=11205&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
3+
[牛客网](https://www.nowcoder.com/practice/28970c15befb4ff3a264189087b99ad4?tpId=13&tqId=11205&tab=answerKey&from=cyc_github)
44

55
## 题目描述
66

@@ -13,22 +13,22 @@
1313
应该注意到,'.' 是用来当做一个任意字符,而 '\*' 是用来重复前面的字符。这两个的作用不同,不能把 '.' 的作用和 '\*' 进行类比,从而把它当成重复前面字符一次。
1414

1515
```java
16-
public boolean match(char[] str, char[] pattern) {
16+
public boolean match(String str, String pattern) {
1717

18-
int m = str.length, n = pattern.length;
18+
int m = str.length(), n = pattern.length();
1919
boolean[][] dp = new boolean[m + 1][n + 1];
2020

2121
dp[0][0] = true;
2222
for (int i = 1; i <= n; i++)
23-
if (pattern[i - 1] == '*')
23+
if (pattern.charAt(i - 1) == '*')
2424
dp[0][i] = dp[0][i - 2];
2525

2626
for (int i = 1; i <= m; i++)
2727
for (int j = 1; j <= n; j++)
28-
if (str[i - 1] == pattern[j - 1] || pattern[j - 1] == '.')
28+
if (str.charAt(i - 1) == pattern.charAt(j - 1) || pattern.charAt(j - 1) == '.')
2929
dp[i][j] = dp[i - 1][j - 1];
30-
else if (pattern[j - 1] == '*')
31-
if (pattern[j - 2] == str[i - 1] || pattern[j - 2] == '.') {
30+
else if (pattern.charAt(j - 1) == '*')
31+
if (pattern.charAt(j - 2) == str.charAt(i - 1) || pattern.charAt(j - 2) == '.') {
3232
dp[i][j] |= dp[i][j - 1]; // a* counts as single a
3333
dp[i][j] |= dp[i - 1][j]; // a* counts as multiple a
3434
dp[i][j] |= dp[i][j - 2]; // a* counts as empty

notes/20. 表示数值的字符串.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 20. 表示数值的字符串
22

3-
[NowCoder](https://www.nowcoder.com/practice/6f8c901d091949a5837e24bb82a731f2?tpId=13&tqId=11206&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
3+
[牛客网](https://www.nowcoder.com/practice/e69148f8528c4039ad89bb2546fd4ff8?tpId=13&tqId=11206&tab=answerKey&from=cyc_github)
44

55
## 题目描述
66

@@ -41,8 +41,8 @@ false
4141
```
4242

4343
```java
44-
public boolean isNumeric(char[] str) {
45-
if (str == null || str.length == 0)
44+
public boolean isNumeric (String str) {
45+
if (str == null || str.length() == 0)
4646
return false;
4747
return new String(str).matches("[+-]?\\d*(\\.\\d+)?([eE][+-]?\\d+)?");
4848
}

0 commit comments

Comments
 (0)