Skip to content

Commit 7d89df1

Browse files
committed
feat: add .gitignore
1 parent 4de91c1 commit 7d89df1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+158
-1275
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
|#|Title|Tag|
7070
|:------------- |:------------- |:------------- |
7171
|4|[Median of Two Sorted Arrays][004]|Array, Binary Search, Divide and Conquer|
72+
|10|[Regular Expression Matching][010]|String, Dynamic Programmin, Backtracking|
7273

7374

7475

@@ -118,3 +119,4 @@
118119
[554]: https://github.com/Blankj/awesome-java-leetcode/blob/master/note/554/README.md
119120

120121
[004]: https://github.com/Blankj/awesome-java-leetcode/blob/master/note/004/README.md
122+
[010]: https://github.com/Blankj/awesome-java-leetcode/blob/master/note/010/README.md

note/010/README.md

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# [Regular Expression Matching][title]
2+
3+
## Description
4+
5+
Implement regular expression matching with support for `'.'` and `'*'`.
6+
7+
```
8+
'.' Matches any single character.
9+
'*' Matches zero or more of the preceding element.
10+
11+
The matching should cover the entire input string (not partial).
12+
13+
The function prototype should be:
14+
bool isMatch(const char *s, const char *p)
15+
16+
Some examples:
17+
isMatch("aa", "a") → false
18+
isMatch("aa", "aa") → true
19+
isMatch("aaa", "aa") → false
20+
isMatch("aa", "a*") → true
21+
isMatch("aa", ".*") → true
22+
isMatch("ab", ".*") → true
23+
isMatch("aab", "c*a*b") → true
24+
```
25+
26+
**Tags:** String, Dynamic Programmin, Backtracking
27+
28+
29+
## 思路0
30+
31+
题意是
32+
33+
``` java
34+
class Solution {
35+
public boolean isMatch(String s, String p) {
36+
if (p.length() == 0) return s.length() == 0;
37+
if (p.contains(".*")) return true;
38+
int sL = s.length(), pL = p.length();
39+
boolean[][] dp = new boolean[sL + 1][pL + 1];
40+
dp[0][0] = true;
41+
for (int i = 1; i < pL; ++i) {
42+
if (p.charAt(i) == '*' && dp[0][i - 1]) {
43+
dp[0][i + 1] = true;
44+
}
45+
}
46+
for (int i = 0; i < sL; ++i) {
47+
for (int j = 0; j < pL; ++j) {
48+
char c1 = s.charAt(i), c2 = p.charAt(j);
49+
if (c2 == '.' || c2 == c1) {
50+
dp[i + 1][j + 1] = dp[i][j];
51+
}
52+
if (c2 == '*') {
53+
c2 = p.charAt(j - 1);
54+
if (c2 == c1 || c2 == '.') {
55+
dp[i + 1][j + 1] = dp[i + 1][j] || dp[i][j + 1] || dp[i + 1][j - 1];
56+
} else {
57+
dp[i + 1][j + 1] = dp[i + 1][j - 1];
58+
}
59+
}
60+
}
61+
}
62+
return dp[sL][pL];
63+
}
64+
}
65+
```
66+
67+
68+
## 结语
69+
70+
如果你同我一样热爱数据结构、算法、LeetCode,可以关注我GitHub上的LeetCode题解:[awesome-java-leetcode][ajl]
71+
72+
73+
74+
[title]: https://leetcode.com/problems/regular-expression-matching
75+
[ajl]: https://github.com/Blankj/awesome-java-leetcode

project/leetcode/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.iml
2+
.idea
3+
.DS_Store
4+
/out

0 commit comments

Comments
 (0)