Your friend is typing his name into a keyboard.  Sometimes, when typing a character c, the key might get long pressed, and the character will be typed 1 or more times.

You examine the typed characters of the keyboard.  Return True if it is possible that it was your friends name, with some characters (possibly none) being long pressed.

Example 1:

Input: name = "alex", typed = "aaleex"
Output: true
Explanation: 'a' and 'e' in 'alex' were long pressed.

Example 2:

Input: name = "saeed", typed = "ssaaedd"
Output: false
Explanation: 'e' must have been pressed twice, but it wasn't in the typed output.

Example 3:

Input: name = "leelee", typed = "lleeelee"
Output: true

Example 4:

Input: name = "laiden", typed = "laiden"
Output: true
Explanation: It's not necessary to long press any character.

Note:

  1. name.length <= 1000
  2. typed.length <= 1000
  3. The characters of name and typed are lowercase letters.
class Solution(object):
def isLongPressedName(self, name, typed):
"""
:type name: str
:type typed: str
:rtype: bool
"""
j=0
for c in name:
if j==len(typed):
return False
if typed[j]!=c:
if j==0 or typed[j-1]!=typed[j]:
return False
cur=typed[j]
while j<len(typed) and typed[j]==cur:
j+=1
if j==len(typed) or typed[j]!=c:
return False
j+=1
return True

  

 

[LeetCode&Python] Problem 925. Long Pressed Name的更多相关文章

  1. [LeetCode&Python] Problem 108. Convert Sorted Array to Binary Search Tree

    Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Fo ...

  2. [LeetCode&Python] Problem 387. First Unique Character in a String

    Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...

  3. [LeetCode&Python] Problem 427. Construct Quad Tree

    We want to use quad trees to store an N x N boolean grid. Each cell in the grid can only be true or ...

  4. [LeetCode&Python] Problem 371. Sum of Two Integers

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  5. [LeetCode&Python] Problem 520. Detect Capital

    Given a word, you need to judge whether the usage of capitals in it is right or not. We define the u ...

  6. [LeetCode&Python] Problem 226. Invert Binary Tree

    Invert a binary tree. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: 4 / \ 7 2 / \ / \ 9 6 3 1 Tr ...

  7. [LeetCode&Python] Problem 905: Sort Array By Parity

    Given an array A of non-negative integers, return an array consisting of all the even elements of A, ...

  8. [LeetCode&Python] Problem 1: Two Sum

    Problem Description: Given an array of integers, return indices of the two numbers such that they ad ...

  9. [LeetCode&Python] Problem 682. Baseball Game

    You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 ...

随机推荐

  1. TCP之种种连接异常

    1. connect出错: (1) 若TCP客户端没有收到syn分节的响应,则返回ETIMEOUT错误:调用connect函数时,内核发送一个syn,若无响应则等待6s后再发送一个,若仍然无响应则等待 ...

  2. bool的值分别为0,1;那哪个代表true哪个代表false?

    0为false,1为true. bool表示布尔型变量,也就是逻辑型变量的定义符,以英国数学家.布尔代数的奠基人乔治·布尔(George Boole)命名. 布尔型变量bool的取值只有false和t ...

  3. VS2015 scanf 函数报错 error C4996: 'scanf'

    错误提示:error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. ...

  4. eclipse Oxygen2 4.7.2版本安装activiti插件,并兼容svn插件

    附录,插件下载:链接:https://pan.baidu.com/s/138ChoXao1fALBzdOhJjdQg 密码:06fx 安装方法: 解压eclipse安装包,将eclipse-activ ...

  5. Learning-Python【21】:Python常用模块(4)—— re、logging、hashlib、subprocess

    re 模块:与正则相关的模块 在使用 re 模块之前,需要先了解正则表达式(regular expression),描述了一种字符串匹配的模式(pattern),可以用来检查一个字符串是否含有某个子字 ...

  6. 微信端修改title

    function setTitle(t) { document.title = t; var i = document.createElement('iframe'); i.src = "i ...

  7. Android:手把手教你 实现Activity 与 Fragment 相互通信,发送字符串信息(含Demo)

    前言Activity 与 Fragment 的使用在Android开发中非常多今天,我将主要讲解 Activity 与 Fragment 如何进行通信,实际上是要解决两个问题: Activity 如何 ...

  8. Tomcat 中 jsp 中文乱码显示处理解决方案

    原地址: http://blog.csdn.net/joyous/article/details/1504274 初学JSP,尤其是Tomcat环境(GlassFish默认UTF-8,则不存在此类问题 ...

  9. JS碰撞检测

    视图理解://div1的上边大于div2的下边,,div1的右边小于div2的左边,,div1的上边大于div2的下边,,div1的左边大于div2的右边,这四种情况,问题是没有碰撞/重叠,如下: & ...

  10. 简述采用四次握手机制释放TCP连接的四个步骤

    (1)源结点A向目的结点B发送连接释放请求(FIN,seg=x),并且不再向B发送数据,但仍继续接收从B发来的数据. (2)目的结点B收到此连接释放请求后立即向A发出确认(ACK,ack=x+1),但 ...