Skip to content

Commit 147f595

Browse files
author
Yeqi Tao
committed
Add soulution.go for 0010.Regular Expression Matching
1 parent af2058a commit 147f595

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
func isMatch(s string, p string) bool {
2+
//p only contains `.` or `*` or `[a-z]`
3+
lenP := len(p)
4+
lenS := len(s)
5+
if lenP == 0 {
6+
return lenS == 0
7+
}
8+
fm := lenS != 0 && (s[0] == p[0] || p[0] == '.')
9+
10+
if len(p) >= 2 && p[1] == '*' {
11+
return isMatch(s, p[2:]) || fm && isMatch(s[1:], p)
12+
} else {
13+
return fm && isMatch(s[1:], p[1:])
14+
}
15+
}

0 commit comments

Comments
 (0)