# 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
public boolean isMatch(String s, String p) {
if(p.length()==0||p==null){
return s==null||s.length()==0;
}
if(s==null){
return false;
}
if(s.length()==0){
if(p.length()%2==1)
return false;
else{
for(int i=0;i<p.length();i++){
if(i%2==1&&p.charAt(i)!='*'){
return false;
}
}
return true;
}
}
if(p.length() == 1){
if(s.length()>1){
return false;
}
if(p.charAt(0) == s.charAt(0)||p.charAt(0)=='.'){
return true;
}
return false;
}
else{
if(p.charAt(1)=='*'){
while(s.length()!=0&&(p.charAt(0)==s.charAt(0)||p.charAt(0)=='.')){
if(isMatch(s,p.substring(2))){
return true;
}
s = s.substring(1);
}
return isMatch(s,p.substring(2));
}
else{
if(p.charAt(0)==s.charAt(0)||p.charAt(0)=='.'){
return isMatch(s.substring(1),p.substring(1));
}
return false;
}
}
}

02-21 2739

12-21 2456

04-15 5750

08-30 8932

09-18 2万

05-19 1135

03-16 2.8万

09-18 1599

03-02 4810

06-11 2139