Leetcode 961 Solution
This article provides solution to leetcode question 961 (long-pressed-name)
Access this page by simply typing in "lcs 961" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/long-pressed-name
Solution
class Solution(object):
def isLongPressedName(self, name, typed):
"""
:type name: str
:type typed: str
:rtype: bool
"""
i = 0
j = 0
while i < len(name) and j < len(typed):
next_i = i + 1
while next_i < len(name) and name[next_i] == name[i]:
next_i += 1
next_j = j + 1
while next_j < len(typed) and typed[next_j] == typed[j]:
next_j += 1
if next_i - i > next_j - j:
return False
i = next_i
j = next_j
return i == len(name) and j == len(typed)