Regular Expression Matching
2016-07-06 10:06
387 查看
public class Solution { public boolean isMatch(String s, String p) { if (p.length() == 0) { return s.length() == 0; } else if (p.length() == 1 || p.charAt(1) != '*') { if (s.length() < 1) { return false; } else if (s.charAt(0) != p.charAt(0) && p.charAt(0) != '.') { return false; } else { return isMatch(s.substring(1), p.substring(1)); } } else { if (isMatch(s, p.substring(2))) { return true; } int i = 0; while (i < s.length() && (s.charAt(i) == p.charAt(0) || p.charAt(0) == '.')) { if (isMatch(s.substring(i + 1), p.substring(2))) { return true; } i++; } return false; } } }
相关文章推荐
- POJ1458【最长公共子序列】
- 在线渗透工具大全
- myeclipse 10破解办法
- float与double的范围和精度
- 在C++中用虚函数的作用是什么?为什么要用到虚函数
- 工作4年了
- 4 Good habits for a succeful life
- 算法_优先队列
- hdwik中view模块的应用
- c# BackGroundWorker 多线程操作的小例子
- activity的信使intent
- poj 2559 单调栈
- coreseek(sphinx)的简单应用以及在LAMP中的注意事项
- 前端打包工具
- 循环的pageview
- 什么是CGI、FastCGI、php-cgi、php-fpm?
- RPC原理及实现
- kvm性能优化方案---cpu/内存/磁盘/网络
- Fragment生命周期
- C. Hexadecimal's Numbers