标签:public offer bsp 包含 ext class wrap 表达式 等于
1 class Solution { 2 public: 3 bool match(char* str, char* pattern) 4 { 5 if(str == NULL || pattern == NULL) 6 { 7 return false; 8 } 9 return matchCore(str,pattern); 10 } 11 bool matchCore(char *str, char *pattern) 12 { 13 if(*str == ‘\0‘ && *pattern == ‘\0‘) 14 return true; 15 if(*str != ‘\0‘ && *pattern == ‘\0‘) 16 return false; 17 if(*(pattern+1) == ‘*‘)//下一位为*(注意优先级问题加()) 18 { 19 if(*pattern == *str || (*pattern == ‘.‘ && *str != ‘\0‘))//当前位匹配 20 { 21 return matchCore(str+1,pattern+2)//匹配一个 22 || matchCore(str+1,pattern)//匹配>=2个 23 || matchCore(str,pattern+2);//匹配0个 24 } 25 else 26 { 27 return matchCore(str,pattern+2);//匹配0个 28 } 29 } 30 if(*str == *pattern ||(*pattern == ‘.‘ && *str !=‘\0‘)) 31 return matchCore(str+1,pattern+1); 32 return false; 33 } 34 };
标签:public offer bsp 包含 ext class wrap 表达式 等于
原文地址:http://www.cnblogs.com/qqky/p/7095168.html