Example:
Input:
S = "heeellooo"
words = ["hello", "hi", "helo"]
Output: 1
Explanation:
We can extend "e" and "o" in the word "hello" to get "heeellooo".
We can't extend "helo" to get "heeellooo" because the group "ll" is not size 3 or more.
class Solution {
public int expressiveWords(String S, String[] words) {
int res = 0;
for (String word: words) {
if (stretchy(S, word)) {
res += 1;
}
}
return res;
} private boolean stretchy(String S, String word) {
int i = 0, j = 0;
while (i < S.length() && j < word.length()) {
if (S.charAt(i) != word.charAt(j)) {
return false;
}
int lenS = getRepeated(i, S);
int lenWord = getRepeated(j, word);
if (lenS < 3 && lenWord != lenS || lenS >= 3 && lenS < lenWord) {
return false;
}
i += lenS;
j += lenWord;
}
return i == S.length() && j == word.length();
} private int getRepeated(int index, String word) {
int i = index;
while (i < word.length() && word.charAt(i) == word.charAt(index)) {
i += 1;
}
return i - index;
}
}

[LC] 809. Expressive Words的更多相关文章

  1. 【LeetCode】809. Expressive Words 解题报告(Python)

    [LeetCode]809. Expressive Words 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http ...

  2. leetcode笔记(五)809. Expressive Words

    题目描述 Sometimes people repeat letters to represent extra feeling, such as "hello" -> &qu ...

  3. 809. Expressive Words

    https://leetcode.com/problems/expressive-words/description/ class Solution { public: int expressiveW ...

  4. leetcode 学习心得 (4)

    645. Set Mismatch The set S originally contains numbers from 1 to n. But unfortunately, due to the d ...

  5. All LeetCode Questions List 题目汇总

    All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...

  6. 四种比较简单的图像显著性区域特征提取方法原理及实现-----> AC/HC/LC/FT。

    laviewpbt  2014.8.4 编辑 Email:laviewpbt@sina.com   QQ:33184777 最近闲来蛋痛,看了一些显著性检测的文章,只是简单的看看,并没有深入的研究,以 ...

  7. “LC.exe”错误

    错误“LC.exe”已退出,代码为 -1. 可能的原因是: 这个第三方组件是个商业组件,他在组件的主使用类定义了 LicenseProvider(typeof(LicFileLicenseProvid ...

  8. 解决VS下“LC.exe已退出,代码为-1”问题

    今天使用VS2015开发一个Winform程序,手一抖拖错了一个第三方控件,然后将其去掉并删除相关的引用,结果导致了LC.exe错误:"Lc.exe已退出,代码为-1 ". 经过上 ...

  9. 解析.NET 许可证编译器 (Lc.exe) 的原理与源代码剖析

    许可证编译器 (Lc.exe) 的作用是读取包含授权信息的文本文件,并产生一个可作为资源嵌入到公用语言运行库可执行文件中的 .licenses 文件. 在使用第三方类库时,经常会看到它自带的演示程序中 ...

随机推荐

  1. PAT Advanced 1018 Public Bike Management (30) [Dijkstra算法 + DFS]

    题目 There is a public bike service in Hangzhou City which provides great convenience to the tourists ...

  2. CSU2004:Finding words(含指定不相交前后缀的模式串计数)

    题:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=2004 题意:给定n个模式串,m个询问,每个询问是“前缀+‘*’+后缀 ”的组合的串S,输出 ...

  3. redis(四)----发布订阅

    发布订阅(pub/sub)是一种消息通信模式,主要的目的是解耦消息发布者和消息订阅者之间的耦合.pub /sub不仅仅解决发布者和订阅者直接代码级别耦合,也解决两者在物理部署上的耦合.废话不多说,直接 ...

  4. 大数据高可用集群环境安装与配置(02)——配置ntp服务

    NTP服务概述 NTP服务器[Network Time Protocol(NTP)]是用来使计算机时间同步化的一种协议,它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)做同步化,它可以提供高精 ...

  5. .net core excel导入导出

    做的上一个项目用的是vs2013,传统的 Mvc模式开发的,excel报表的导入导出都是那几段代码,已经习惯了. 导入:string filename = ExcelFileUpload.FileNa ...

  6. 更新anaconda包

    升级安装python环境后, 把老的包重新安装回去. ls -l /opt/anaconda3/lib/python3.7/site-packages/ | grep "\-info&quo ...

  7. 在vSphere群集中配置EVC的注意事项

    原路径:https://blog.51cto.com/wangchunhai/2084434 个人觉得有一点写的有出入: 2 vCenter保存在本地存储中,无共享存储 中主机图片和描述信息有异常. ...

  8. protobuf 的enum与string转换

    c/c++ enum 介绍 说起c/c++ 的enum,比起python 真的是方便简洁 enum type{ type1 = 0, type2 } enum的元素对应的int 默认从0 开始依次增加 ...

  9. JavaScript—暂告,小节

    Javastript 的学习告一段落了.虽然还有更多的:爬虫 什么的    但是和我在学校的相比 要扎实许多.知道了兼容性 面向对象,闭包.....一些细节的用法. 虽然以后可能很少用到.可是我觉得 ...

  10. luogu P3835 【模板】可持久化平衡树

    #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> usin ...