LeetCode 10: Regular Expression Matching
2015-06-01 23:15
543 查看
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; }else{ while(*s && (*s==*p || *p=='.')) { if(isMatch(s, p+2)) return true; s++; } return isMatch(s, p+2); } return false; } };
相关文章推荐
- JComboBox
- uva 10494 高精度除法
- FOJ 1342 Tight Words
- powerdesign 常用技巧
- Memory-mapped I/O vs port-mapped I/O
- day2 - 编写数据库模块
- Cocos2d-x 详解坐标系统
- 【转载】二十款好看的css字体样式
- 线段树初识&hdu 1166 敌兵布阵
- Linux 压缩,解压缩,打包与解包
- Web 前端
- URAL 1039 Anniversary Party 树形DP 水题
- viewWillAppear
- MSDEPLOYAGENTSERVICE) could not be contacted.
- LeetCode 1. twoSums
- [Emacs学习笔记]停止与撤销
- python2《=》python3 某些库函数互相转换的个人总结 =>持续更新
- LeetCode 8: Palindrome Number
- 经典统计语言模型
- chrome插件:实现任意窗口,显示特定icon