Skip to content

Commit 316c09d

Browse files
committed
925. 长按键入
1 parent e9c8e39 commit 316c09d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

str/925_isLongPressedName.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution:
2+
def isLongPressedName(self, name: str, typed: str) -> bool:
3+
m, n = len(name), len(typed)
4+
if n < m:
5+
return False
6+
7+
i = j = 0
8+
while j < n:
9+
if i < m and name[i] == typed[j]:
10+
i += 1
11+
j += 1
12+
elif j > 0 and typed[j] == typed[j - 1]:
13+
j += 1
14+
else:
15+
return False
16+
return i == m
17+
18+
19+
if __name__ == '__main__':
20+
name = "alex"
21+
typed = "alexxr"
22+
solution = Solution()
23+
print(solution.isLongPressedName(name, typed))

0 commit comments

Comments
 (0)