Leetcode925.Long Pressed Name长按键入
你的朋友正在使用键盘输入他的名字 name。偶尔,在键入字符 c 时,按键可能会被长按,而字符可能被输入 1 次或多次。
你将会检查键盘输入的字符 typed。如果它对应的可能是你的朋友的名字(其中一些字符可能被长按),那么就返回 True。
示例 1:
输入:name = "alex", typed = "aaleex" 输出:true 解释:'alex' 中的 'a' 和 'e' 被长按。
示例 2:
输入:name = "saeed", typed = "ssaaedd" 输出:false 解释:'e' 一定需要被键入两次,但在 typed 的输出中不是这样。
示例 3:
输入:name = "leelee", typed = "lleeelee" 输出:true
示例 4:
输入:name = "laiden", typed = "laiden" 输出:true 解释:长按名字中的字符并不是必要的。
提示:
- name.length <= 1000
- typed.length <= 1000
- name 和 typed 的字符都是小写字母。
class Solution {
public:
bool isLongPressedName(string name, string typed)
{
int len1 = name.size();
int len2 = typed.size();
int cnt = 0;
for(int i = 0; i < len2; i++)
{
if(name[cnt] == typed[i])
{
cnt++;
if(cnt >= len1)
break;
}
else
{
int j;
for(j = i + 1; j < len2; j++)
{
if(typed[j] != typed[i])
{
break;
}
}
if(j >= len2)
return false;
if(typed[j] != name[cnt])
return false;
i = j - 1;
}
}
if(cnt < len1)
return false;
return true;
}
};
Leetcode925.Long Pressed Name长按键入的更多相关文章
- [LeetCode] 925. Long Pressed Name 长按键入的名字
Your friend is typing his name into a keyboard. Sometimes, when typing a character c, the key might ...
- [Swift]LeetCode925. 长按键入 | Long Pressed Name
Your friend is typing his name into a keyboard. Sometimes, when typing a character c, the key might ...
- leetcode 925. 长按键入
题目描述: 你的朋友正在使用键盘输入他的名字 name.偶尔,在键入字符 c 时,按键可能会被长按,而字符可能被输入 1 次或多次. 你将会检查键盘输入的字符 typed.如果它对应的可能是你的朋友的 ...
- 力扣(LeetCode)长按键入 个人题解
你的朋友正在使用键盘输入他的名字 name.偶尔,在键入字符 c 时,按键可能会被长按,而字符可能被输入 1 次或多次. 你将会检查键盘输入的字符 typed.如果它对应的可能是你的朋友的名字(其中一 ...
- JAVA 之 每日一记 之 算法 ( 长按键入 )
题目详解: 你的朋友正在使用键盘输入他的名字 name.偶尔,在键入字符 c 时,按键可能会被长按,而字符可能被输入 1 次或多次. 你将会检查键盘输入的字符 typed.如果它对应的可能是你的朋友的 ...
- Swift LeetCode 目录 | Catalog
请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift 说明:题目中含有$符号则为付费题目. 如 ...
- vim 命令
命令历史 以:和/开头的命令都有历史纪录,可以首先键入:或/然后按上下箭头来选择某个历史命令. 启动vim 在命令行窗口中输入以下命令即可 vim 直接启动vim vim filename 打开vim ...
- Vim命令合集大全
命令历史 以:和/开头的命令都有历史纪录,可以首先键入:或/然后按上下箭头来选择某个历史命令. 启动vim 在命令行窗口中输入以下命令即可 vim 直接启动vim vim filename 打开vim ...
- vim操作集合
Vim命令合集 命令历史 以:和/开头的命令都有历史纪录,可以首先键入:或/然后按上下箭头来选择某个历史命令. 启动vim 在命令行窗口中输入以下命令即可 vim 直接启动vim vim filena ...
随机推荐
- CAS企业级单点登录原理
https://blog.csdn.net/anumbrella/article/details/80821486 1. 单点登录概述 1.1. 什么是单点登录? 单点登录:Single Sign O ...
- vue-admin-template模板添加tagsview
参考: https://github.com/PanJiaChen/vue-admin-template/issues/349 一.从vue-element-admin复制文件: vue-admin- ...
- 牛客NOIP暑期七天营-TG1 赛后题解
目录 牛客NOIP暑期七天营-提高组1 A-最短路 题目描述 link 题解 代码 B-最小生成链 题目描述 link 题解 代码 C-最小字典最短路 题目描述 link 题解 Update 牛客NO ...
- Ubuntu时间管理方法
1. date 命令主要用于显示以及修改系统时间 2. hwclock 命令用于查看设置硬件时间,以及同步硬件时间与系统时间 # 显示硬件时间hwclock # 设置硬件时间hwclock -set ...
- mysql5.7在线更改innodb_buffer_pool_size
show variables like 'innodb_buffer_pool_size'; set global innodb_buffer_pool_size=;# 在线更改该值时,不会立即生效, ...
- Python 编码转换与中文处理
python 中的 unicode是让人很困惑.比较难以理解的问题. 这篇文章 写的比较好,utf-8是 unicode的一种实现方式,unicode.gbk.gb2312是编码字符集. py文件中的 ...
- @NotNull,@NotBlank和 @NotEmpty使用
1.实体类 package com.example; import org.hibernate.validator.constraints.NotBlank; import org.hibernate ...
- 【agc013d】AtCoder Grand Contest 013 D - Piling Up
题意 盒子里有n块砖,每块的颜色可能为蓝色或红色. 执行m次三步操作: 1.从盒子里随便拿走一块砖 2.放入一块蓝砖和红砖到盒子里 3.从盒子里随便拿走一块砖 给定n,m 问拿出来的砖,可能有多少种不 ...
- 桥接模式(Bridge、Implementor)(具体不同平台日志记录,抽象与实现分离)
桥接模式(Bridge Pattern):将抽象部分与它的实现部分分离,使它们都可以独立地变化.它是一种对象结构型模式,又称为柄体(Handle and Body)模式或接口(Interface)模式 ...
- spring-注解配置-junit整合测试-aop
1 使用注解配置spring 1.1 步骤 导包4+2+spring-aop 1.为主配置文件引入新的命名空间(约束) 2.开启使用注解代理配置文件 3.在类中使用注解完成配置 1.2 将对象注册到容 ...