Skip to content
LC-0925 Easy LeetCode

925. Long Pressed Name

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 32% Topics: Two Pointers, String
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

class Solution(object):
    def isLongPressedName(self, name, typed):
        """
        :type name: str
        :type typed: str
        :rtype: bool
        """
        i = 0
        for j in xrange(len(typed)):
            if i < len(name) and name[i] == typed[j]:
                i += 1
            elif j == 0 or typed[j] != typed[j-1]:
                return False
        return i == len(name)

Solution from kamyu104/LeetCode-Solutions · MIT