'?' Matches any single character.
'*' Matches any sequence of characters (including the empty sequence).

字符串匹配问题。

如上所示:其中 ‘ ?’ 可以匹配任何一个单字符    ’ * ‘ 可以匹配任意长度的字符包括空字符串
 给定字符串s,和字符串p。判断按照以上规则,字符串p是否能够匹配字符串s
 
 
参考代码: 
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(字符串匹配问题)的更多相关文章

  1. LeetCode - 44. Wildcard Matching

    44. Wildcard Matching Problem's Link --------------------------------------------------------------- ...

  2. 第八周 Leetcode 44. Wildcard Matching 水题 (HARD)

    Leetcode 44 实现一种类似正则表达式的字符串匹配功能. 复杂度要求不高, 调代码稍微费点劲.. 好像跟贪心也不太沾边, 总之 *把待匹配串分成若干个子串, 每一个子串尽量在模式串中靠前的部分 ...

  3. [LeetCode] Wildcard Matching 字符串匹配,kmp,回溯,dp

    Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...

  4. [LeetCode] 44. Wildcard Matching 外卡匹配

    Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '? ...

  5. [leetcode]44. Wildcard Matching万能符匹配

    Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '? ...

  6. leetcode 44. Wildcard Matching(模糊匹配)

    搬运工了- - https://blog.csdn.net/jmspan/article/details/51460021

  7. leetcode 10. Regular Expression Matching 、44. Wildcard Matching

    10. Regular Expression Matching https://www.cnblogs.com/grandyang/p/4461713.html class Solution { pu ...

  8. leetcode笔记 动态规划在字符串匹配中的应用

    目录 leetcode笔记 动态规划在字符串匹配中的应用 0 参考文献 1. [10. Regular Expression Matching] 1.1 题目 1.2 思路 && 解题 ...

  9. 44. Wildcard Matching

    题目: Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single charact ...

随机推荐

  1. 常用的js 总结

    1.点击一个按钮,跳转到新页面 $("#btnCancel").click(function(){ location.href="${ctx}/engine/formul ...

  2. MySQL时间戳时间

    MySQL中: now():获取当前时间:例:SELECT now(); unix_timestamp():将时间转换为时间戳:例: SELECT unix_timestamp(now());

  3. Python入门学习:网络刷博器爬虫

    1.比较有趣,可以不断刷新指定的网址 2.源码: #!/usr/bin/env python3 # -*- coding: utf-8 -*- import webbrowser as web imp ...

  4. mac ssh中文乱码解决

    网上有如下解决法,至少我没有成功过: vim ~/.bash_profile export LC_ALL='zh_CN.utf8' 来源:http://www.liuhuadong.com/archi ...

  5. maven pom文件详解

    http://www.blogjava.net/hellxoul/archive/2013/05/16/399345.html http://blog.csdn.net/houpengfei111/a ...

  6. Android学习之——单击ActionBar实现ListView返回顶部

    不知道大家在刷微博时,有没有遇到过,刷新太多,想返回顶部看之前的微博的情况.其实,单击顶部的ActionBar能返回顶部.而不用一直向下拉. 废话不多说,讲讲Android中怎么实现这一功能. 首先, ...

  7. 查询SQL阻塞语句

    SELECT SPID=p.spid, DBName = convert(CHAR(),d.name), ProgramName = program_name, LoginName = convert ...

  8. workerman定时器使用 php定时任务

    add int \Workerman\Lib\Timer::add(float $time_interval, callable $callback [,$args = array(), bool $ ...

  9. 【Mongodb】用户和认证 权限总结

    开启MongoDB服务时不添加任何参数时,默认是没有权限验证的,登录的用户可以对数据库任意操作而且可以远程访问数据库!   在刚安装完毕的时候MongoDB都默认有一个admin数据库,此时admin ...

  10. 使用pycharm,追求最优的代码。

    1.最近追求的是代码0警告,没有任何提示. 怎么追求这样的目标,不需要再去单独使用pylint和flake8这些玩意,只需要看pycharm右边编辑区的竖向滚动条的黄色就可以了. 2. 比较糟糕的就是 ...