美文网首页
154. Regular Expression Matching

154. Regular Expression Matching

作者: 鸭蛋蛋_8441 | 来源:发表于2019-07-13 04:28 被阅读0次

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第二个为*号时的处理。

代码:

相关文章

网友评论

      本文标题:154. Regular Expression Matching

      本文链接:https://www.haomeiwen.com/subject/fraukctx.html