题目描述: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

代码如下:

class Solution {
public:
bool isMatch(const char *s, const char *p) { if(*p == '\0') return *s == '\0'; //如果下一个字符不是*,那么就需要匹配当前的字符!
if(*(p + 1) != '*'){ //下一个字符相等,或者有一个是'.',则匹配成功
if(*p == *s || (*p == '.' && *s != '\0'))
return isMatch(s + 1, p + 1);
else
return false;
} //下一个字符是*,则当前字符可以为0个或多个!
else{
while(*p == *s || (*p == '.' && *s != '\0')){
if(isMatch(s, p + 2))
return true;
s++;
}
return isMatch(s, p + 2);
} }
};

最新文章

  1. .NET平台机器学习资源汇总,有你想要的么?
  2. Odoo domain 中的 like, ilike, =like, =ilike 举例说明【转】
  3. Java面向对象思想解决猜拳问题
  4. curl get post 数据
  5. NopCommerce 3.80框架研究(一) 数据访问与持久化
  6. 从malloc中窥探Linux内存分配策略
  7. 改变UIView 的位置 Center和Frame
  8. MySQL原生HA方案 – Fabric体验之旅
  9. hadoop2.2.0伪分布模式64位安装
  10. bash的元字符(下)
  11. Spring笔记 - Bean xml装配
  12. org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.entity.annotations.House.district in
  13. Mycat 分片规则详解--枚举分片
  14. 从零开始学TensorFlow
  15. JavaScript的文档对象模型DOM
  16. Vue : Expected the Promise rejection reason to be an Error
  17. 手机与PC的影音相互播放(DLNA/UPNP)
  18. tomcat-maven-plugin的使用
  19. JS模拟下拉框select
  20. 学习POC框架pocsuite--编写hellowordPOC

热门文章

  1. 03 . Gin+Vue开发一个线上外卖应用(用户数据创建,插入,跨域处理)
  2. Java学习的第四十三天
  3. hadoop使用实例
  4. Masking Personal Information
  5. fasd
  6. c++ templates 第二版(英文)
  7. ES6 小记
  8. 像用excel一样用pandas
  9. HTTPDNS开源 Android SDK,赋能更多开发者参与共建
  10. Spring源码解析之BeanFactoryPostProcessor(一)