1 class Solution(object): 2 def isLongPressedName(self, name, typed): 3 """ 4 :type name: str 5 :type typed: str 6 :rtype: bool 7 """ 8 i, j = 0, 0 9 while j < len(typed): 10 if i < len(name) and name[i] == typed[j]: 11 i += 1 12 j += 1 13 elif j > 0 and typed[j] == typed[j - 1]:#首字母相同的前提下,若type有重复的话 14 j += 1 15 else: 16 return False 17 18 return i == len(name)