leetcode925
public class Solution
{
public bool IsLongPressedName(string name, string typed)
{
var list1 = new List<KeyValuePair<char, int>>();
var list2 = new List<KeyValuePair<char, int>>(); int name_len = name.Length;
int typed_len = typed.Length;
if (name_len > typed_len)
{
return false;
}
int con = ;
var last_char = ' ';
for (int i = ; i < name_len - ; i++)
{
var cur_char = name[i];
var next_char = name[i + ];
last_char = next_char;
if (cur_char == next_char)
{
con++;
}
else
{
list1.Add(new KeyValuePair<char, int>(cur_char, con));
con = ;
}
}
list1.Add(new KeyValuePair<char, int>(last_char, con)); con = ;
last_char = ' ';
for (int i = ; i < typed_len - ; i++)
{
var cur_char = typed[i];
var next_char = typed[i + ];
last_char = next_char;
if (cur_char == next_char)
{
con++;
}
else
{
list2.Add(new KeyValuePair<char, int>(cur_char, con));
con = ;
}
}
list2.Add(new KeyValuePair<char, int>(last_char, con));
if (list1.Count > list2.Count)
{
return false;
}
for (int i = ; i < list1.Count; i++)
{
if (list1[i].Key != list2[i].Key || list1[i].Value > list2[i].Value)
{
return false;
}
}
return true;
}
}
leetcode925的更多相关文章
- [Swift]LeetCode925. 长按键入 | Long Pressed Name
Your friend is typing his name into a keyboard. Sometimes, when typing a character c, the key might ...
- Leetcode925.Long Pressed Name长按键入
你的朋友正在使用键盘输入他的名字 name.偶尔,在键入字符 c 时,按键可能会被长按,而字符可能被输入 1 次或多次. 你将会检查键盘输入的字符 typed.如果它对应的可能是你的朋友的名字(其中一 ...
随机推荐
- php取浮点数后两位的方法
$num = 10.4567; //第一种:利用round()对浮点数进行四舍五入echo round($num,2); //10.46 //第二种:利用sprintf格式化字符串$format_nu ...
- RAC5——11gR2以后GI进程的变化
参考文档: 11gR2 Clusterware and Grid Home - What You Need to Know (Doc ID 1053147.1)诊断 Grid Infrastructu ...
- JUC线程池之 ThreadPoolExecutor简介
ThreadPoolExecutor简介 ThreadPoolExecutor是线程池类.对于线程池,可以通俗的将它理解为"存放一定数量线程的一个线程集合.线程池允许若个线程同时允许,允许同 ...
- Nginx 下部署 HTTPS 与安全调优
什么是 HTTPS?# HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的 ...
- php 图片剪切
<?php /** * 图像裁剪 * @param $source_path 原图路径 * @param $target_width 需要裁剪的宽 * @param $target_height ...
- C#之设计模式之六大原则
一.单一职责原则 原文链接:http://blog.csdn.net/lovelion/article/details/7536542 单一职责原则是最简单的面向对象设计原则,它用于控制类的粒度大小. ...
- 【python】class之类的内建函数
- 解决Qt Creator编译输出窗口乱码的问题
设置环境变量LC_ALL为en_US. 附注:将乱码复制到文本编辑器(如Notepad++)后将编码设置为utf-8,可以看到正确的文字. 看样子是编译输出窗口的编码设置出了问题,或者是gcc的输出编 ...
- POJ 3666 Making the Grade (线性dp,离散化)
Making the Grade Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) T ...
- 术语-服务:PaaS
ylbtech-术语-服务:PaaS PaaS是Platform-as-a-Service的缩写,意思是平台即服务. 把服务器平台作为一种服务提供的商业模式.通过网络进行程序提供的服务称之为SaaS( ...