LeetCode 44 Wildcard Matching(字符串匹配问题)
'?' Matches any single character.
'*' Matches any sequence of characters (including the empty sequence).
字符串匹配问题。
package leetcode_50; /***
*
* @author pengfei_zheng
* 字符串匹配问题
*/
public class Solution44 {
public boolean isMatch(String s, String p) {
int sp = 0, pp = 0, match = 0, starIdx = -1;
while (sp < s.length()){
if (pp < p.length() && (p.charAt(pp) == '?'
|| s.charAt(sp) == p.charAt(pp))){
sp++;
pp++;
}
else if (pp < p.length() && p.charAt(pp) == '*'){
starIdx = pp;
match = sp;
pp++;
}
else if (starIdx != -1){
pp = starIdx + 1;
match++;
sp = match;
}
else return false;
}
while (pp < p.length() && p.charAt(pp) == '*')
pp++; return pp == p.length();
}
}
LeetCode 44 Wildcard Matching(字符串匹配问题)的更多相关文章
- LeetCode - 44. Wildcard Matching
44. Wildcard Matching Problem's Link --------------------------------------------------------------- ...
- 第八周 Leetcode 44. Wildcard Matching 水题 (HARD)
Leetcode 44 实现一种类似正则表达式的字符串匹配功能. 复杂度要求不高, 调代码稍微费点劲.. 好像跟贪心也不太沾边, 总之 *把待匹配串分成若干个子串, 每一个子串尽量在模式串中靠前的部分 ...
- [LeetCode] Wildcard Matching 字符串匹配,kmp,回溯,dp
Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...
- [LeetCode] 44. Wildcard Matching 外卡匹配
Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '? ...
- [leetcode]44. Wildcard Matching万能符匹配
Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '? ...
- leetcode 44. Wildcard Matching(模糊匹配)
搬运工了- - https://blog.csdn.net/jmspan/article/details/51460021
- leetcode 10. Regular Expression Matching 、44. Wildcard Matching
10. Regular Expression Matching https://www.cnblogs.com/grandyang/p/4461713.html class Solution { pu ...
- leetcode笔记 动态规划在字符串匹配中的应用
目录 leetcode笔记 动态规划在字符串匹配中的应用 0 参考文献 1. [10. Regular Expression Matching] 1.1 题目 1.2 思路 && 解题 ...
- 44. Wildcard Matching
题目: Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single charact ...
随机推荐
- Opengl的gl_NormalMatrix
原文地址:http://blog.csdn.net/ichild1964/article/details/9728357 参考:http://www.gamedev.net/topic/598985- ...
- Junit结合Spring对Dao层进行单元测试
关于单元测试,上一次就简单的概念和Mock基础做了,参考:http://60.174.249.204:8888/in/modules/article/view.article.php/74 实际开发过 ...
- java rpc
一.简介 Hessian和Burlap是由Caucho Technology提供的基于HTTP协议的轻量级远程服务解决方案.他们都致力于借助尽可能简单那的API和通信协议来简化Web服务. He ...
- BarTender表单的人性化设计—分组框
BarTender 2016已经支持用户输入信息.从相同位置查询数据库和筛选数据记录,那就是数据输入表单了.这个功能相信迎合了很多用户的需求,主要作用体现在打印时数据输入. 对于表单的设计,不同的客户 ...
- 安装 运行yum报错:No module named yum
报错情况: There was a problem importing one of the Python modulesrequired to run yum. The error leading ...
- python--面向对象--14
原创博文,转载请标明出处--周学伟http://www.cnblogs.com/zxouxuewei/ Python 面向对象 Python从设计之初就已经是一门面向对象的语言,正因为如此,在Pyth ...
- AngularJS------使用VSCode创建的Angular项目部署IIS
转载: http://www.cnblogs.com/kingkangstudy/p/7699710.html 1.进入项目src,执行命令行:ng build 2.步骤1后会生成dist文件 3.打 ...
- web.xml 整合 SpringMVC
啦啦啦 <context-param> <param-name>defaultHtmlEscape</param-name> <param-value> ...
- Netty权威指南之NIO通信模型
NIO简介:与Socket和ServerSocket类相对应,NIO提供了SocketChannel和ServerSocketChannel两种不同的套接字通道实现,这两种新通道都支持阻塞和非阻塞两种 ...
- window.open被拦截
1)直接调用window.open 或 点击的时候直接调用 window.open 是不会被拦截的 // 不会被拦截$('.btn-open').click(function(){ window.op ...