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. 设计模式理解(九)结构型——外观(Facade)

    等了好久,终于想起来开写了,这次写的是外观模式,记得大学时弄课程设计,外观模式搞得我比较混乱,因为单词不认识,后来觉得有点蛋疼,感觉是一坨混乱的东西然后加个壳再弄几个外部调用的接口而已.个人认为,Fa ...

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

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

  3. Pandas之分组

    假如我们现在有这样一组数据:星巴克在全球的咖啡店信息,如下图所示.数据来源:starbucks_store_locations.我们想要统计中国每个城市的星巴克商店的数量,那我们应该怎么做呢? 在pa ...

  4. 深入学习IOZone【转】

    本文转载自:https://blog.csdn.net/werm520/article/details/7262103 深入学习IOZone 刘智朋       2011-3-29 1        ...

  5. [CodeForces 471A] MUH and Sticks

    题目链接:http://codeforces.com/problemset/problem/471/A 题目数据规模1 - 9,可以用一个数组进行计数,减掉出现四次的数,看看还有几个是非零数,有一个就 ...

  6. 剑指offer 04:重构二叉树

    题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7, ...

  7. GPU并行的基础知识

  8. 第八届蓝桥杯省赛 K倍区间

    问题描述 给定一个长度为N的数列,A1, A2, ... AN,如果其中一段连续的子序列Ai, Ai+1, ... Aj(i <= j)之和是K的倍数,我们就称这个区间[i, j]是K倍区间. ...

  9. hdu 1558 Segment set 线段相交+并查集

    Segment set Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Prob ...

  10. 《SQL 基础教程》第四章:数据更新

    数据更新包括了表存在的情况下数据的添加,数据的删除和数据的更新,主要是下面三个语句: INSERT 语句 DELETE 语句 UPDATE 语句 在本章的最后,讲了关于「事务」的相关知识,用于对作出的 ...