Skip to content

Commit 2da8695

Browse files
author
liwentian
committed
fd
1 parent dc83931 commit 2da8695

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

doc/Summary.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@
99
- **207. Course Schedule**
1010
- **210. Course Schedule II**
1111
- **269. Alien Dictionary**
12+
13+
# BackTracking
14+
- **10. Regular Expression Matching**
1215

google/RECORDS.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
2017-9-3
22

3-
`
4-
332. Reconstruct Itinerary(Pending)
5-
`
63
310. Minimum Height Trees
74
399. Evaluate Division
85
261. Graph Valid Tree
96
323. Number of Connected Components in an Undirected Graph
10-
7+
10. Regular Expression Matching
118

129
2017-9-2
1310
329. Longest Increasing Path in a Matrix
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.leetcode.google;
2+
3+
/**
4+
* Created by liwentian on 2017/9/3.
5+
*/
6+
7+
public class RegularExpressionMatching {
8+
9+
public boolean isMatch(String s, String p) {
10+
if (p.isEmpty()) {
11+
return s.isEmpty();
12+
}
13+
if (p.length() == 1) {
14+
return s.length() == 1 && equals(s, p);
15+
}
16+
if (p.charAt(1) != '*') {
17+
return s.length() > 0 && equals(s, p) && isMatch(s.substring(1), p.substring(1));
18+
}
19+
if (s.isEmpty() || !equals(s, p)) {
20+
return isMatch(s, p.substring(2));
21+
} else {
22+
return isMatch(s, p.substring(2)) || isMatch(s.substring(1), p);
23+
}
24+
}
25+
26+
private boolean equals(String s, String p) {
27+
return p.charAt(0) == '.' || s.charAt(0) == p.charAt(0);
28+
}
29+
}

0 commit comments

Comments
 (0)