题解 | #正则表达式匹配#
正则表达式匹配
https://www.nowcoder.com/practice/28970c15befb4ff3a264189087b99ad4
package main func match( str string , pattern string ) bool { if len(pattern) == 0 { return len(str) == 0 } firstMatch := len(str) > 0 && (pattern[0] == str[0] || pattern[0] == '.') if len(pattern) == 1 { return len(str) == 1 && firstMatch } if pattern[1] == '*' { if !firstMatch { return match(str, pattern[2:]) } return match(str, pattern[2:]) || match(str[1:], pattern) } return firstMatch && match(str[1:], pattern[1:]) }