forked from someshgkale123/LeetCode-Easy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Long Pressed Name
40 lines (31 loc) · 1.1 KB
/
Long Pressed Name
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Problem Statement:
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.
Solution:
class Solution:
def isLongPressedName(self, name: str, typed: str) -> bool:
flag=[]
new=iter(typed)
for i in name:
if i in new:
flag.append(True)
else:
flag.append(False)
return all(flag)