[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 文件. 在使用第三方类库时,经常会看到它自带的演示程序中 ...
随机推荐
- 51nod 1346:递归
1346 递归 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 关注 函数f(n,m) { 若n=1或m=1返回a[n][m]; 返回f(n-1,m)异或 ...
- delphi 串口的打开与关闭
Delphi 打开串口与关闭串口 procedure TForm1.btn1Click(Sender: TObject); begin cm1.CommName:=cbb1.Text; cm1.Bau ...
- MySQL 存储引擎(MyISAM、InnoDB、NDBCluster)
前言 MySQL 的存储引擎可能是所有关系型数据库产品中最具有特色的了,不仅可以同时使用多种存储引擎,而且每种存储引擎和MySQL之间使用插件方式这种非常松的耦合关系. 由于各存储引擎功能特性差异较大 ...
- python + selenium +win32gui + winspy 实现图片上传
过程:模拟点击上传按钮,打开Windows对话框,编辑栏输入文件路径(或网址)点击确定.网上随便找了一个进行测试. 点击后出现Windows上传对话框 用 winspy 来检测窗口的句柄 python ...
- 磁盘报No space left on device,但是 df -h 查看磁盘空间没满
df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/dev01-root 75G 58G 14G 82% / udev 2.0G ...
- UML-基于GRASP对象设计步骤
在OO设计建模的时候,在最后考虑系统启动时需要初始化的内容. 1.从用例开始,以下是一步步设计用例实现 处理销售 2.SSD 我们选择: makeNewSale 3.编写操作契约(复杂用例场景时) 4 ...
- 学生信息管理系统java测试报告
package studentinformation; /**姓名 胡海靖 * 学号 20183609 * 班级 信1805-2 */ class ScoreInformation { private ...
- 通过ES6 封装了一个上传文件的方法 XMLHttpRequest() 通用
### 上传进度回显,上传速度回显 ### 源码如下,新建index.js装起来 export class UploadServers { constructor (options) { this.x ...
- C++ 11新标准实现POJ No.2195-GoingHome
Going Home(回家)(标签:二部图,匈牙利算法,KM算法) 题目描述 在网格地图上,有n个男人和n个房屋. 在每个单位时间内,每个小人都可以水平或垂直移动一个单位步长到相邻的点. 对于每个小人 ...
- Python 模拟 Base64编码
Base64编码原理:https://blog.csdn.net/wo541075754/article/details/81734770 def Enbs64(s): # 编码后的结果 result ...