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. VUE.js入门学习(5)- 插槽和作用域插槽

    插槽: (1)用法 以前的写法:如果内容很多的话,就很烂了- 插槽写法:(PS:组建名不能用保留关键字) (2)具名插槽 (3)作用域插槽 必须template开始和结尾,这个插槽要声明我从子组建接收 ...

  2. go 汇编

    汇编文件 go tool compile -S main.go>main.S go tool compile 可以看帮助 -N 关闭优化

  3. setoolkit+花生壳 制作钓鱼网站

    国家法律一定要遵守,知识要用在对的地方. 本贴只为了和大家交流学习,请勿用在其他地方,损害任何人的利益. 今天我,来说一下钓鱼网站 (在kali) 我们选择  1  回车 再选择 2 回车 再选择3 ...

  4. @Autowired注解与@Resource注解的区别(详细)

    相信对现在Java码农来说,@Autowired跟@Resource并不陌生,二者都可以自动注入,但是两者的区别很多时候并没有被注意到. 一.注解的出处 @Autowired是Spring提供的注解, ...

  5. 白痴级教程,新手看过来,具详细实操文档 (word图片复制不过来,0202年了还有这样的不便利,下回研究一下,图片下次补)

    一.环境配置(win10): 1.配置cmd的python环境为arcmap10.2 自带的python解释器(2.7.3)(自带arcpy库) 具体操作: 1我的电脑右击属性,打开 (选中path点 ...

  6. CodeForces-1100C NN and the Optical Illusion 简单数学

    题目链接:https://vjudge.net/problem/CodeForces-1100C 题意: 题目给出外部圆的数目n和内部圆的半径r,要求求出外部圆的半径以满足图片要求. 显然这是一道数学 ...

  7. Mybatis学习——Mybatis入门程序

    MyBatis入门程序 一.查询用户 1.使用客户编号查询用户 (1).创建一个数据表 USE spring; #创建一个名为t_customer的表 CREATE TABLE t_customer( ...

  8. UML-领域模型-准则

    1.是否使用工具维护模型? 在白板上画完草图后,整理到UML工具里去 2.模型中是否要包含“票据”? 不包含,因为,票据用于退货,而本次迭代不涉及退货所以不需要体现. 总结:概念一定在本次迭代需求内的 ...

  9. 寒假day05-spring框架

    1.回顾事务 l 事务:一组业务操作ABCD,要么全部成功,要么全部不成功. l 特性:ACID 原子性:整体 一致性:完成 隔离性:并发 持久性:结果 l 隔离问题: 脏读:一个事务读到另一个事务没 ...

  10. 框架-Spring容器

    1.   Spring Ioc容器 容器是Spring框架的基础,容器会创建.串联.配置对象,并且能管理对象的整个生命周期.如下是代表 Spring工作原理 MetaData 指定哪些对象实例化.配置 ...