2025-08-01 13:53:59 +0000 UTC
Long Pressed Name
Categories:
Links
Code
class Solution:
def isLongPressedName(self, name: str, typed: str) -> bool:
name_i, typed_i = 0, 0
name_length, typed_length = len(name), len(typed)
while name_i < name_length and typed_i < typed_length:
if name[name_i] == typed[typed_i]:
name_i += 1
typed_i += 1
elif typed_i >= 1 and typed[typed_i] == typed[typed_i - 1]:
typed_i += 1
else:
return False
if name_i != name_length:
return False
while typed_i < typed_length:
if typed[typed_i] != typed[typed_i - 1]:
return False
typed_i += 1
return True