Created
December 17, 2017 19:27
-
-
Save jianminchen/4bdeb0e09bd300e4364b5b9d04741a46 to your computer and use it in GitHub Desktop.
regular expression - using dynamic programming analysis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Case 1: char matches = isMatch[i-1][j-1] && s[si] == p[pi] | |
// S "aa" "aa" | |
// P "aa" "ba" | |
// Case 2: dot matches = isMatch[i-1][j-1] && p[pi] == '.' | |
// S "aa" "aa" | |
// P "a." "b." | |
// Case 1 & Case 2 can be combined | |
// Case 3: * | |
// 3a - 0 matches | |
// s: "a" or "b" or "" or "b" | |
// p: "ax*" "ax*" "x*" ".*" | |
// T F T T | |
// isMatch = isMatch[i][j-2] | |
// 3b - 1 match | |
// s: "ax" or "bx" or "ab" or "ab" | |
// p: "ax*" "ax*" "a.*" or "c.*" | |
// T F T F | |
// isMatch = isMatch[i-1][j-2] && s[si] == p[pi - 1] || p[pi - 1] == '.' | |
// 3c - 1+ match | |
// s: "xx" or "xxx" or "bx" or "bbx" | |
// p: "x*" "x*" "x*" "x*" | |
// T T F F | |
// 1 will be handled in 1 match and the rest will succeed because of 0 match | |
// isMatch = isMatch[i-1][j] && s[si] == p[pi - 1] || p[pi - 1] == '.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment