###### Leetcode-Regular Expression Matching

Implement regular expression matching with support for ‘.’ and ‘*’.

‘.’ Matches any single character.
‘*’ Matches zero or more of the preceding element.

The matching should cover the entire input string (not partial).

The function prototype should be:
bool isMatch(const char *s, const char *p)

Some examples:
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
DP

bool isMatch(string s, string p) {
int sl=s.length();
int pl=p.length();

vector<vector<bool>> dp(pl+1,vector<bool>(sl+1,false));
dp[0][0]=true;

for(int i=1;i<=pl;++i)
{
dp[i][0]=i-2>=0&&p[i-1]=='*'&&dp[i-2][0];
for(int j=1;j<=sl;++j)
{
if(p[i-1]==s[j-1]||p[i-1]=='.')
{
dp[i][j]=dp[i-1][j-1];
}
else if(p[i-1]=='*'&&i-2>=0)
{
if(dp[i-2][j]||((p[i-2]==s[j-1]||p[i-2]=='.')&&dp[i][j-1]))
{
dp[i][j]=true;
}
else
{
dp[i][j]=false;
}
}
else
{
dp[i][j]=false;
}

}

}
return dp[pl][sl];

}

#### **LeetCode-Regular Expression Matching

2015-10-23 09:02:51

#### LeetCode-Regular Expression Matching

2014-08-18 19:55:07

#### leetcode-Regular Expression Matching

2014-03-21 15:00:55

#### 10. Regular Expression Matching（很重要!!!）

2016-08-15 17:15:09

#### LeetCode题解--10. Regular Expression Matching

2016-04-03 11:40:23

#### leetcode 10: Regular Expression Matching 分析及解答

2016-07-22 20:56:43

#### [LeetCode] 010. Regular Expression Matching (Hard) (C++/Java/Python)

2015-03-02 11:20:51

#### 《LeetBook》leetcode题解(10): Regular Expression Matching——DP解决正则匹配

2016-04-15 21:50:01

#### 10. Regular Expression Matching-动态规划/递归回溯

2016-09-11 21:40:08

#### Regular Expression Matching -- LeetCode

2014-03-16 16:16:06

## 不良信息举报

Leetcode-Regular Expression Matching