最近做leetcode总感觉自己是个智障,基本很少有题能自己独立做出来,都是百度。。。

不过终于还是做出了一题。。。而且速度效率还可以

哎,加油吧,尽量锤炼自己

package y2019.Algorithm.str.medium;

import java.util.ArrayList;
import java.util.List; /**
* @Auther: xiaof
* @Date: 2019/11/21 09:00
* @Description: 1023. Camelcase Matching
*
* A query word matches a given pattern if we can insert lowercase letters to the pattern word so that it equals the query.
* (We may insert each character at any position, and may insert 0 characters.)
* Given a list of queries, and a pattern, return an answer list of booleans,
* where answer[i] is true if and only if queries[i] matches the pattern.
*
* Example 1:
* Input: queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FB"
* Output: [true,false,true,true,false]
* Explanation:
* "FooBar" can be generated like this "F" + "oo" + "B" + "ar".
* "FootBall" can be generated like this "F" + "oot" + "B" + "all".
* "FrameBuffer" can be generated like this "F" + "rame" + "B" + "uffer".
* Example 2:
* Input: queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FoBa"
* Output: [true,false,true,false,false]
* Explanation:
* "FooBar" can be generated like this "Fo" + "o" + "Ba" + "r".
* "FootBall" can be generated like this "Fo" + "ot" + "Ba" + "ll".
* Example 3:
* Input: queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FoBaT"
* Output: [false,true,false,false,false]
* Explanation:
* "FooBarTest" can be generated like this "Fo" + "o" + "Ba" + "r" + "T" + "est".
*
*/
public class CamelMatch { /**
* myself
* Runtime: 0 ms, faster than 100.00% of Java online submissions for Camelcase Matching.
* Memory Usage: 34.7 MB, less than 100.00% of Java online submissions for Camelcase Matching.
* @param queries
* @param pattern
* @return
*/
public List<Boolean> solution(String[] queries, String pattern) { List<Boolean> res = new ArrayList<>();
//比较所有的字符
//1.长度pattern肯定是不比queriers长的
for (int i = 0; i < queries.length; ++i) {
res.add(match(queries[i], pattern));
} return res;
} public boolean match(String des, String pattern) {
//1.顺序比较字符,当所有的字符被des匹配成功,那么就ok,并且不能存在大写的字符留存
int index1 = 0, index2 = 0;
while (index1 < des.length() && index2 < pattern.length()) {
char desc1 = des.charAt(index1);
char p1 = pattern.charAt(index2);
//如果匹配成功,那么直接进入下一个字符
if (desc1 == p1) {
index1++;
index2++;
} else {
//如果第一个匹配失败
if (desc1 - 'a' >= 0 && desc1 - 'z' <= 0) {
//如果是小写
//2.如果是小写,那么进入下一个字符
index1++;
} else {
//1.判断字符是否小写,如果是大写
//如果大写字符不匹配,那么就直接false
return false;
}
}
}
//如果判断剩下的是否有大写
while (index1 < des.length()) {
char desc1 = des.charAt(index1);
if (desc1 - 'a' >= 0 && desc1 - 'z' <= 0) {
//如果是小写
//2.如果是小写,那么进入下一个字符
index1++;
} else {
return false;
}
} return index2 >= pattern.length();
} // ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"]
// "FB"
public static void main(String[] args) {
String[] s = {"FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"};
String pattern = "FB";
CamelMatch fuc = new CamelMatch(); fuc.solution(s, pattern); } }

【LEETCODE】70、字符匹配1023 Camelcase Matching的更多相关文章

  1. leetcode 44 字符匹配

    题意:s是空串或包含a-z字母: p为包含a-z字母或?或 * (其中*可以匹配任意字符串包括空串,?可以匹配任意字符). 思路: 1)特殊情况:当s为空串时,p为连续 * 时,则连续 * 的位置都为 ...

  2. 【LeetCode】1023. Camelcase Matching 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 正则+字典 日期 题目地址:https://leet ...

  3. 1023. Camelcase Matching驼峰式匹配

    网址:https://leetcode.com/problems/camelcase-matching/ 依题意可得逻辑 class Solution { public: vector<bool ...

  4. Leetcode 1023. Camelcase Matching

    暴力查找 class Solution: def camelMatch(self, queries: List[str], pattern: str) -> List[bool]: q_size ...

  5. 【leetcode】1023. Camelcase Matching

    题目如下: A query word matches a given pattern if we can insert lowercaseletters to the pattern word so ...

  6. LeetCode 44. 通配符匹配(Wildcard Matching)

    题目描述 给定一个字符串 (s) 和一个字符模式 (p) ,实现一个支持 '?' 和 '*' 的通配符匹配. '?' 可以匹配任何单个字符. '*' 可以匹配任意字符串(包括空字符串). 两个字符串完 ...

  7. Leetcode 10. 正则表达式匹配 - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...

  8. Java实现 LeetCode 10 正则表达式匹配

    10. 正则表达式匹配 给你一个字符串 s 和一个字符规律 p,请你来实现一个支持 '.' 和 '*' 的正则表达式匹配. '.' 匹配任意单个字符 '*' 匹配零个或多个前面的那一个元素 所谓匹配, ...

  9. 【编程题目】有 n 个长为 m+1 的字符串,如果某个字符串的最后 m 个字符与某个字符串的前 m 个字符匹配...

    37.(字符串)有 n 个长为 m+1 的字符串,如果某个字符串的最后 m 个字符与某个字符串的前 m 个字符匹配,则两个字符串可以联接,问这 n 个字符串最多可以连成一个多长的字符串,如果出现循环, ...

随机推荐

  1. Reactive Extensions (Rx) 入门(1) —— Reactive Extensions 概要

    译文:https://blog.csdn.net/fangxing80/article/details/7381619 原文:http://www.atmarkit.co.jp/fdotnet/int ...

  2. VUE 基础配置

    原文:https://www.cnblogs.com/LearningOnline/p/9368838.html 1.安装Node.js等软件 报错: 解决: 原文:https://pdf-lib.o ...

  3. luogu P1550 [USACO08OCT]打井Watering Hole

    题目背景 John的农场缺水了!!! 题目描述 Farmer John has decided to bring water to his N (1 <= N <= 300) pastur ...

  4. exception java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

      1.情景展示 Java 报错信息如下: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 2.原因分析 首先,这是越界异常,但不是数组越 ...

  5. maven 无法引入包 报错 处理方式

    <!--orderquery thrift client定义--> <dependency> <groupId>com.sankuai.qcs</groupI ...

  6. Self-Supervised Representation Learning

    Self-Supervised Representation Learning 2019-11-11 21:12:14  This blog is copied from: https://lilia ...

  7. mysql知识集锦

    1.mysql中InnoDB引擎中页的概念 2.mysql索引详解--如何从磁盘中读取索引文件

  8. Python爬虫实例项目

    WechatSogou [1]- 微信公众号爬虫.基于搜狗微信搜索的微信公众号爬虫接口,可以扩展成基于搜狗搜索的爬虫,返回结果是列表,每一项均是公众号具体信息字典. DouBanSpider [2]- ...

  9. 【转】PostgreSQL与MySQL比较

    转自:https://www.cnblogs.com/geekmao/p/8541817.html PostgreSQL与MySQL比较   特性 MySQL PostgreSQL 实例 通过执行 M ...

  10. odoo开发笔记 -- 还原数据库后,异常:ir_attachment: IOError: [Errno 2] No such file or directory: u'/var/...'

    场景描述: 恢复Odoo数据后,抛出错误导致无法进入页面 -- ::, INFO aeo odoo.addons.base.ir.ir_attachment: _read_file reading / ...