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 ...
随机推荐
- 2019-2-13-Latex-论文elsevier,手把手如何用Latex写论文
title author date CreateTime categories Latex 论文elsevier,手把手如何用Latex写论文 lindexi 2019-02-13 10:38:20 ...
- 获取计算机以及本机信息API
获取计算机名: BOOL GetComputerName( LPTSTR lpBuffer, // computer name LPDWORD lpnSize // size of name buff ...
- Ionic 微信支付
1.安装插件 ionic plugin add https://github.com/mrwutong/cordova-qdc-wxpay.git 2.代码 controller.js angular ...
- [转载] 使用C/C++语言编写基于DSP程序的注意事项
原文地址:『转』使用C/C++语言编写基于DSP程序的注意事项作者:skysmile 1.不影响执行速度的情况下,可以使用c或c/c++语言提供的函数库,也可以自己设计函数,这样更易于使用“裁缝师 ...
- 关于python中 and 和 or 的一些特殊使用
print(True or 1) # True print(1 or True) # 1 print(3 or 1) # 3 print(0 or 3) # 3 总结:or左边无论是 数字还是Boo ...
- css之页面三列布局之左右两边宽度固定,中间自适应
左右两边宽度固定,中间自适应 左右两边绝对定位 可以利用浮动,左边的左浮动,右边的右浮动 css3 flex布局(html http://www.cnblogs.com/myzy/p/5919814. ...
- javaWeb-监听器Listener
监听器Listener (一)监听器Listener javaEE包括13门规范 在课程中主要学习 servlet技术 和 jsp技术 其中 servlet规范包括三个技术点:servlet lis ...
- NPM:如何配置maven npm私服
https://help.sonatype.com/repomanager3/quick-start-guide-proxying-maven-and-npm#QuickStartGuide-Prox ...
- bzoj 1053 [HAOI2007]反素数ant——关于质数的dfs / 打表
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1053 写了个打表程序. #include<iostream> #include& ...
- localStorage对象简单应用 - - 访问次数
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...