LeetCode_10---Regular Expression Matching
来源:互联网 发布:g92锥度螺纹编程 编辑:程序博客网 时间:2024/06/05 21:01
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") → falseisMatch("aa","aa") → trueisMatch("aaa","aa") → falseisMatch("aa", "a*") → trueisMatch("aa", ".*") → trueisMatch("ab", ".*") → trueisMatch("aab", "c*a*b") → true
实现正规表达式,不是很明白,有空仔细研究一下
Code:
public class Solution { public boolean isMatch(String s, String p) { if (p.isEmpty()) { return s.isEmpty(); } if (p.length() == 1 || p.charAt(1) != '*') { if (s.isEmpty() || (p.charAt(0) != '.' && p.charAt(0) != s.charAt(0))) { return false; } else { return isMatch(s.substring(1), p.substring(1)); } } //P.length() >=2 while (!s.isEmpty() && (s.charAt(0) == p.charAt(0) || p.charAt(0) == '.')) { if (isMatch(s, p.substring(2))) { return true; } s = s.substring(1); } return isMatch(s, p.substring(2)); }}
0 0
- LeetCode_10---Regular Expression Matching
- LeetCode_10 Regular Expression Matching
- leetcode_10. Regular Expression Matching ? 待解决
- LeetCode: Regular Expression Matching
- LeetCode: Regular Expression Matching
- leetcode Regular Expression Matching
- [Leetcode] Regular Expression Matching
- Regular Expression Matching
- Regular Expression Matching
- [LeetCode]Regular Expression Matching
- Regular Expression Matching
- LeetCode-Regular Expression Matching
- Regular Expression Matching
- Regular Expression Matching LeetCode
- Regular Expression Matching
- LeetCode | Regular Expression Matching
- LeetCode: Regular Expression Matching
- Leetcode: Regular Expression Matching
- 四轴飞行器之气压传感器
- [徐有高 -2015]徐有高:2005年-2015年全国“两会”汽车行业焦点声音
- 基于运算的排序:计数排序
- 使用jasperreports制作报表(导出pdf excel html)
- Objective-C编码规范:26个方面解决iOS开发问题
- LeetCode_10---Regular Expression Matching
- Java基本数据类型
- Linux FTP安装与简单配置
- map和set异同
- 简明python教程:第2章 安装Python
- silverlight路径的动态展示
- CentOS搭建shadowsocks-libev服务端
- SSI2整合,spring和xfire 整合之后,加入Struts2 上传下载功能
- 一致性hash算法释义