[LC] 809. Expressive Words
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的更多相关文章
- 【LeetCode】809. Expressive Words 解题报告(Python)
[LeetCode]809. Expressive Words 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http ...
- leetcode笔记(五)809. Expressive Words
题目描述 Sometimes people repeat letters to represent extra feeling, such as "hello" -> &qu ...
- 809. Expressive Words
https://leetcode.com/problems/expressive-words/description/ class Solution { public: int expressiveW ...
- leetcode 学习心得 (4)
645. Set Mismatch The set S originally contains numbers from 1 to n. But unfortunately, due to the d ...
- All LeetCode Questions List 题目汇总
All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...
- 四种比较简单的图像显著性区域特征提取方法原理及实现-----> AC/HC/LC/FT。
laviewpbt 2014.8.4 编辑 Email:laviewpbt@sina.com QQ:33184777 最近闲来蛋痛,看了一些显著性检测的文章,只是简单的看看,并没有深入的研究,以 ...
- “LC.exe”错误
错误“LC.exe”已退出,代码为 -1. 可能的原因是: 这个第三方组件是个商业组件,他在组件的主使用类定义了 LicenseProvider(typeof(LicFileLicenseProvid ...
- 解决VS下“LC.exe已退出,代码为-1”问题
今天使用VS2015开发一个Winform程序,手一抖拖错了一个第三方控件,然后将其去掉并删除相关的引用,结果导致了LC.exe错误:"Lc.exe已退出,代码为-1 ". 经过上 ...
- 解析.NET 许可证编译器 (Lc.exe) 的原理与源代码剖析
许可证编译器 (Lc.exe) 的作用是读取包含授权信息的文本文件,并产生一个可作为资源嵌入到公用语言运行库可执行文件中的 .licenses 文件. 在使用第三方类库时,经常会看到它自带的演示程序中 ...
随机推荐
- MyBatis:使用注解开发
面向接口编程 大家之前都学过面向对象编程,也学习过接口,但在真正的开发中,很多时候我们会选择面向接口编程 根本原因 : 解耦 , 可拓展 , 提高复用 , 分层开发中 , 上层不用管具体的实现 , 大 ...
- Spring装配Bean的一些高级技巧
一.使用@Profile注解来实现在不同环境下创建不同的Bean 实现方式:将不同的Bean定义整理到对应环境的Profile中,当应用部署到不同的环境时(开发环境或者是QA环境或者是生产环境),激活 ...
- BMP位图图像格式简介
1. 文件结构 位图文件可看成由4个部分组成:位图文件头(bitmap-fileheader).位图信息头(bitmap-informationheader).彩色表(colortable)和定义位图 ...
- A4纸网页打印
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- php日期时间戳,日期函数使用
date_default_timezone_get():获得当前php的时区 date_default_timezone_set():设置当前php的时区 date("Y-m-d H-i-s ...
- py02_04:三元运算法
a if a > b else c # a>b 成立,则为真,如果a>b为假,则返回c
- 开发大型项目必备 98%公司都在用的十佳 Java Web 应用框架
众所周知,工欲善其事,必先利其器.选择一个好的 Web 应用框架就像一把称手的兵器,可以助大家披荆斩棘. 今天就为大家整理了十佳 Java Web 应用框架,并简单讨论一下它们的优缺点. 第一,大名鼎 ...
- Hadoop的常用指令
-help:查看帮助 hadoop fs -help rm -rm [-f] [-r|-R] [-skipTrash] <src> ... : Delete all files that ...
- 第37章 socket编程 之练习:实现简单的web服务器
一.参考网址 1.linux C学习之实现简单的web服务器 2.C语言实现简单Web服务器(一)
- Istio流量治理原理之负载均衡
流量治理是一个非常宽泛的话题,例如: ● 动态修改服务间访问的负载均衡策略,比如根据某个请求特征做会话保持: ● 同一个服务有两个版本在线,将一部分流量切到某个版本上: ● 对服务进行保护,例如限制并 ...