Wildcard Matching leetcode java
题目:
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的更多相关文章
- Regular Expression Matching leetcode java
题目: Implement regular expression matching with support for '.' and '*'. '.' Matches any single chara ...
- Wildcard Matching - LeetCode
Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...
- LeetCode: Wildcard Matching 解题报告
Wildcard MatchingImplement wildcard pattern matching with support for '?' and '*'. '?' Matches any s ...
- [Leetcode][Python]44:Wildcard Matching
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 44:Wildcard Matchinghttps://oj.leetcode ...
- 【LeetCode】44. Wildcard Matching (2 solutions)
Wildcard Matching Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any ...
- [LeetCode][Facebook面试题] 通配符匹配和正则表达式匹配,题 Wildcard Matching
开篇 通常的匹配分为两类,一种是正则表达式匹配,pattern包含一些关键字,比如'*'的用法是紧跟在pattern的某个字符后,表示这个字符可以出现任意多次(包括0次). 另一种是通配符匹配,我们在 ...
- 【leetcode】Wildcard Matching
Wildcard Matching Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any ...
- LeetCode - 44. Wildcard Matching
44. Wildcard Matching Problem's Link --------------------------------------------------------------- ...
- [LeetCode] Wildcard Matching 题解
6. Wildcard Matching 题目 Implement wildcard pattern matching with support for '?' and '*'. '?' Matche ...
随机推荐
- js原型鏈與js繼承解析
最近在網上看了諸多js原型鏈的解析,說得雲裡霧裡,不明所以.徹底了解後,決定出個博客記錄一下,一是方便後來人學習,二是方便日後複習. 首先,我們來看一下構造函數.原型.實例之間的關係圖: 所以,我們通 ...
- Ural 2045. Richness of words 打表找规律
2045. Richness of words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2045 Description For ...
- Linux学习笔记06—系统用户及用户组的管理
一.认识/etc/passwd和/etc/shadow 1./etc/passwd 由 ‘:’ 分割成7个字段,每个字段的具体含义是: 用户名 存放账号的口令:现在存放在/etc/shadow下,在这 ...
- OS X - 在80端口启动Nginx
不知道你是怎么在你的mac上安装nginx的,但是如果你跟我一样: brew install nginx 然后你会发现你的nginx.conf中的端口是8080. 于是你可能像我一样试着把端口改为80 ...
- Elasticsearch 实现自定义排序插件
插件入口: package ttd.ugc.plugin; import org.elasticsearch.plugins.Plugin;import org.elasticsearch.scrip ...
- CentOS 7开机不执行/etc/rc.local的解决方法
该死的CentOS 7居然开机不执行/etc/rc.local!!!!! 解决: chmod +x /etc/rc.d/rc.local 问题分析: 其实在/etc/rc.lacal文件上已经说明了, ...
- PHP之PDO_MYSQL扩展安装步骤(转)
看到CakePHP文档要求安装pdo_mysql扩展,于是就尝试安装了一下. 这里我的系统是CentOS 6.0.如果你的系统是其他版本的Linux/Unix,可以参考.如果你的系统是Windows的 ...
- [Go] defer 语句
Go 还有一些特有的流程控制语句,其中一个就是 defer 语句.该语句用于延迟调用指定的函数,它只能出现在函数的内部,由 defer 关键字以及针对某个函数的调用表达式组成.这里被调用的函数称为 延 ...
- delphi下实现ribbon界面的方法(一)
http://www.cnblogs.com/shanmx/archive/2011/12/04/2275213.html
- 让TQ2440也用上设备树(2)
作者 作者:彭東林 郵箱:pengdonglin137@163.com QQ:405728433 软件版本 Linux-4.10.17 概述 在之前的博客里介绍了TQ2440上移植设备树的方法,其实, ...