-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString10.java
More file actions
57 lines (55 loc) · 1.4 KB
/
String10.java
File metadata and controls
57 lines (55 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package string;
/**
* @ProjectName: leetcode
* @Package: string
* @ClassName: String10
* @Author: markey
* @Description:
* @Date: 2020/5/1 18:25
* @Version: 1.0
*/
public class String10 {
public boolean isMatch(String s, String p) {
int sIndex = s.length() - 1;
int pIndex = p.length() - 1;
for (; pIndex >= 0; pIndex--) {
if (sIndex < 0) {
break;
}
if (p.charAt(pIndex) == '.') {
sIndex--;
continue;
}
if (p.charAt(pIndex) == '*') {
pIndex--;
char x = p.charAt(pIndex);
if (x == '.') {
return true;
}
while (sIndex >= 0) {
if (s.charAt(sIndex) == x) {
sIndex--;
} else {
break;
}
}
continue;
}
if (p.charAt(pIndex) == s.charAt(sIndex)) {
sIndex--;
} else {
return false;
}
}
// s没匹配完
if (sIndex >= 0) {
return false;
}
// 检查p还有没有
System.out.println(pIndex);
while (pIndex >= 0 && p.charAt(pIndex) == '*') {
pIndex -= 2;
}
return pIndex < 0;
}
}