[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 文件. 在使用第三方类库时,经常会看到它自带的演示程序中 ...
随机推荐
- MFC下的网络编程(1)CAsyncSocket进行无连接(UDP)通信
服务器端发送数据给客户端 先看服务器端: CAsyncSocket m_sockSend; //声明一个Socket对象 点击发送数据后,执行下面这些动作 ...
- 用python3读csv文件出现UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd6 in position 0: invalid continuation byte
1.python3读取csv文件时报如下图所示的错误 2.分析原因:读取的csv文件不是 UTF8 编码的,而IDE工具默认采用 UTF8 解码.解决方法是修改源文件的解码方式. 3.使用nodepa ...
- ADO多线程数据库查询
{ADO查询多线程单元} unit ADOThread; interface uses Classes,StdCtrls,ADODB; type TADOThread = class(TThread) ...
- WOJ 1542 Countries 并查集转化新点+最短路
http://acm.whu.edu.cn/land/problem/detail?problem_id=1542 今天做武大的网赛题,哎,还是不够努力啊,只搞出三个 这个题目一看就是个最短路,但是题 ...
- SQLServer多条件查询技巧
2019-10-15 13:31:04 在实际项目开发中,有很多页面都会出现多条件查询功能,类似于这种情况: 牵扯到数据就少不了数据库了.这么多条件的查询,如果要用常规的if else来写判断逻辑的 ...
- Git 报错:Updates were rejected because the tip of your current branch is behind
刚开始学习 git 命令,发现会出现很多的错误,所以就总结下出现的错误,以此来加深理解和掌握吧! 环境:在本地库操作了一系列的 add 和 commit 操作后,想把本地仓库推送到远端,但是发生以下错 ...
- Python语言基础与应用 (P16)上机练习:基本数据类型
本文是笔者在学习MOOC课程<Python语言基础与应用> (北京大学-陈斌)中根据上机课时的要求写下在代码 课程总链接: 中国大学MOOC B站 本节课链接 数值基本运算: 33和7+, ...
- 向mysql数据库中插入数据时显示“Duplicate entry '1′ for key ‘PRIMARY' ”错误
错误情况如题,出现这个错误的原因十分简单: 很明显,这是主键的问题. 在一张数据表中是不能同时出现多个相同主键的数据的 这就是错误的原因,解决的方法: 1.可以将这张表设置成无主键(mysql支持,其 ...
- 基于Token的身份验证
最近了解下基于 Token 的身份验证,跟大伙分享下.很多大型网站也都在用,比如 Facebook,Twitter,Google+,Github 等等,比起传统的身份验证方法,Token 扩展性更强, ...
- 201409-2 画图 Java
思路: 法1:计算每个矩形的小方块,去掉重复的 法2:二维数组,需要涂色就置flag为1,最后遍历输出,不会有重复计算 import java.util.Scanner; public class M ...