Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
re.search solution in Clear category for Long Pressed by EdinsonUwU
import re
def long_pressed(text: str, typed: str) -> bool:
index_typed = 0
index_text = 0
last_index = False
if text == typed:
return False
for i in text:
if index_text == len(text)-1:
last_index = True
if (not last_index):
if text[index_text] != text[index_text+1]:
if(i == typed[index_typed]):
index_typed += re.search(r'{letter}+'.format(letter=i),typed[index_typed:]).end()
else:
return False
else:
if(i == typed[index_typed] and i == typed[index_typed+1]):
try:
if (i == typed[index_typed] and i == typed[index_typed+1] and i == typed[index_typed+2]):
index_typed += re.search(r'{letter}+'.format(letter=i),typed[index_typed:]).end()-2
except IndexError:
index_typed += re.search(r'{letter}+'.format(letter=i),typed[index_typed:]).end()-1
else:
return False
else:
if(i == typed[index_typed]) and (index_typed == len(typed)-1):
return True
else:
return False
index_text = 1 + index_text
March 2, 2023
Comments: