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 ...
随机推荐
- memcached能获取所有的key吗
memcached能获取所有的key吗 Memcache 查看列出所有key方法 Memcached中获取所有的key 特别要注意:memcached保存的值需要序列化,否则是无法保存的,而且是不会报 ...
- thinkphp 外部js语言包
Thinkphp php文件也外部js文件公用同一个语言包 一 . php语言包转json数据格式 1.新建验证字段的语言包 application\common\lang\validate-cn.p ...
- java新手的session初体验
众所周知,session作为保存我们用户对话所需要的信息的对象,在我们的项目中必不可少.作为菜鸟学习java的第一课就是了解它的思想和用法,在以后的学习中,逐渐学习和总结,从基础到高级,慢慢学会应用. ...
- ios模拟器已安装但xcode无法显示
最近把系统抹盘重装了, 然后用Time Machine恢复到原始状态, 一切安好, 但是使用xcode的时候发现一个模拟器都没有了: 各种折腾, 重装SDK啊, 重装xcode啊,最后发现, 如果你的 ...
- 【NLP】文本相似度
http://www.ruanyifeng.com/blog/2013/03/cosine_similarity.html
- 本地文件到通过flume到hdfs
配置文件 cd /usr/app/flume1.6/conf vi flume-dirTohdfs.properties #agent1 name agent1.sources=source1 age ...
- node配置自动监测文件改变不重启
方法一: nodemon npm install -g nodemon nodemon ./bin/www 或者在npm start命令里把node改为nodemon 方法二:supervisor n ...
- Android Studio配置设置
文章来源:http://www.cnblogs.com/smyhvae/p/4390905.html
- 【乐呵一下】WINDOWS有个非常低级的错误!
该错误来自微软windows附带的计算器(开始附件计算器). 1. 当你尝试用9216除以96并按下=按钮时,计算器竟然没有反应!!! 而9216除以97,98却正常. 2. 还有一个错误,当你尝试用 ...
- 关于移位运算符>>和<<
首先,移位运算符有三种,其操作类型只支持:byte / short / char / int和long五种. << 左移运算符,表示将左边的操作数的二进制数据向左移动*位,移动后空缺位以0 ...