Description
Implement regular expression matching with support for '.' and '*'.
'.' Matches any single character.'*' Matches zero or more of the preceding element.
The matching should cover theentireinput string (not partial).
The function prototype should be:
bool isMatch(string s, string p)
isMatch("aa","a") → false
isMatch("aa","aa") → true
isMatch("aaa","aa") → false
isMatch("aa", "a*") → true
isMatch("aa", ".*") → true
isMatch("ab", ".*") → true
isMatch("aab", "c*a*b") → true 这里c*代表0个c,于是是true
Example
Example 1:
Input:"aa","a"
Output:false
Explanation:
unable to match
Example 2:
Input:"aa","a*"
Output:true
Explanation:
'*' can repeat a
思路:
和192题类似,就是思考起来有点麻烦,尤其是source为空时,对于pattern模式的判断,还有pattern第二个为*号时的处理。
代码:
网友评论