题目

Implement wildcard pattern matching with support for '?' and '*'.

'?' Matches any single character.
'*' Matches any sequence of characters (including the empty sequence). 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") → false
isMatch("aa","aa") → true
isMatch("aaa","aa") → false
isMatch("aa", "*") → true
isMatch("aa", "a*") → true
isMatch("ab", "?*") → true
isMatch("aab", "c*a*b") → false 题解
本文代码引用自:http://blog.csdn.net/perfect8886/article/details/22689147
 1     public boolean isMatch(String s, String p) {  
 2         int i = 0;  
 3         int j = 0;  
 4         int star = -1;  
 5         int mark = -1;  
 6         while (i < s.length()) {  
 7             if (j < p.length()  
 8                     && (p.charAt(j) == '?' || p.charAt(j) == s.charAt(i))) {  
 9                 ++i;  
                 ++j;  
             } else if (j < p.length() && p.charAt(j) == '*') {  
                 star = j++;  
                 mark = i;  
             } else if (star != -1) {  
                 j = star + 1;  
                 i = ++mark;  
             } else {  
                 return false;  
             }  
         }  
         while (j < p.length() && p.charAt(j) == '*') {  
             ++j;  
         }  
         return j == p.length();  
     }
 

Wildcard Matching leetcode java的更多相关文章

  1. Regular Expression Matching leetcode java

    题目: Implement regular expression matching with support for '.' and '*'. '.' Matches any single chara ...

  2. Wildcard Matching - LeetCode

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

  3. LeetCode: Wildcard Matching 解题报告

    Wildcard MatchingImplement wildcard pattern matching with support for '?' and '*'. '?' Matches any s ...

  4. [Leetcode][Python]44:Wildcard Matching

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 44:Wildcard Matchinghttps://oj.leetcode ...

  5. 【LeetCode】44. Wildcard Matching (2 solutions)

    Wildcard Matching Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any ...

  6. [LeetCode][Facebook面试题] 通配符匹配和正则表达式匹配,题 Wildcard Matching

    开篇 通常的匹配分为两类,一种是正则表达式匹配,pattern包含一些关键字,比如'*'的用法是紧跟在pattern的某个字符后,表示这个字符可以出现任意多次(包括0次). 另一种是通配符匹配,我们在 ...

  7. 【leetcode】Wildcard Matching

    Wildcard Matching Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any ...

  8. LeetCode - 44. Wildcard Matching

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

  9. [LeetCode] Wildcard Matching 题解

    6. Wildcard Matching 题目 Implement wildcard pattern matching with support for '?' and '*'. '?' Matche ...

随机推荐

  1. BZOJ2973 : 石头游戏

    考虑到$lcm(1,2,3,4,5,6)=60$,所以操作序列每60秒一个循环. 将操作表示成转移矩阵的形式,预处理出前60秒的转移矩阵以及它们的乘积$B$. 那么t秒的转移矩阵为前$t\bmod 6 ...

  2. Springboot 线程池配置

    最近的项目里要手动维护线程池,然后看到一起开发的小伙伴直接用Java了,我坚信Springboot不可能没这功能,于是查了些资料,果然有,这里给一下. 首先我们都知道@Async标签能让方法异步执行, ...

  3. 如何利用Reveal神器查看各大APP UI搭建层级

    作者 乔同X2016.08.22 19:45 写了3195字,被42人关注,获得了73个喜欢 如何利用Reveal神器查看各大APP UI搭建层级 字数413 阅读110 评论0 喜欢5 title: ...

  4. dp和px,那些不得不吐槽的故事——Android平台图片文字元素单位浅析 (转)

    一个优秀的手机软件,不仅要有精巧的功能,流畅的速度,让人赏心悦目的UI也往往是用户选择的重要理由.作为移动产品的PM,也需要了解一些在UI设计中的基本知识. 1. px和pt,一对好伙伴 在视觉设计中 ...

  5. HappyJTAG2 - JTAG AND SPI AVR8 interface EMBEDDED JTAG ! EMBEDDED SPI !

    New version released ! V2.45 (Check version list for details) This construction is based on HappyJTA ...

  6. 利用kettle组件导入excel文件到数据库

    利用kettle组件导入excel文件到数据库 1.     实现目标 把excel文件内容导入到目标表中:然后用java调用kettle的转换.excel文件的内容仅仅有两列,示比例如以下: wat ...

  7. <label>标签引起的Firefox焦点问题

    在使用Dreamweaver做页面form的时候,默认情况下Dreamweaver都会生成一个<label>标签把元素包装一下,但是有事由于包装不好也会出现一些问题,例如我现在遇到的问题: ...

  8. 完美.PCK文件不完全详解

    building.pck:建筑物 configs.pck:配置文件interface.pck:玩过魔兽的都晓得这个是什么~interface顾名思义·facedata.pck,人物脸型,细节.不要改, ...

  9. 用xcode 5 开发访问IOS 7上面的通讯录有问题

    NSMutableArray *addressBookTemp = [NSMutableArray array]; ABAddressBookRef addressBooks = ABAddressB ...

  10. Linux学习9-CentOS搭建nginx环境

    前言 之前我们搭建网站的时候,把war包放到tomcat下就能运行起来了,为什么部署上线的时候,又用到了nginx呢? nginx可以做多台服务器的负载均衡,当用户非常少的时候,可以用一台服务直接部署 ...