Skip to content

Latest commit

 

History

History
27 lines (21 loc) · 482 Bytes

regular-expression-matching.md

File metadata and controls

27 lines (21 loc) · 482 Bytes

Code

func isMatch(s string, p string) bool {
	if len(p) == 0 {
		return len(s) == 0
	}

	firstMatch := false

	if s != "" && (p[0] == s[0] || string(p[0]) == ".") {
		firstMatch = true
	}

	if len(p) >= 2 && string(p[1]) == "*" {
		return isMatch(s, p[2:]) || (firstMatch && isMatch(s[1:], p))
	} else {
		return firstMatch && isMatch(s[1:], p[1:])
	}
}

Solution

Solution on leetcode