Skip to content

Commit d8e677a

Browse files
authored
Create long-pressed-name.py
1 parent 7c60543 commit d8e677a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Python/long-pressed-name.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def isLongPressedName(self, name, typed):
6+
"""
7+
:type name: str
8+
:type typed: str
9+
:rtype: bool
10+
"""
11+
i = 0
12+
for j in xrange(len(typed)):
13+
if i < len(name) and name[i] == typed[j]:
14+
i += 1
15+
elif j == 0 or typed[j] != typed[j-1]:
16+
return False
17+
return i == len(name)

0 commit comments

Comments
 (0)