925. Long Pressed Name
https://leetcode.com/problems/long-pressed-name/
Your friend is typing his name
into a keyboard. Sometimes, when typing a character c
, the key might get long pressed, and the character will be typed 1 or more times.
You examine the typed
characters of the keyboard. Return True
if it is possible that it was your friends name, with some characters (possibly none) being long pressed.
Example 1:
Example 2:
Example 3:
Example 4:
Constraints:
1 <= name.length <= 1000
1 <= typed.length <= 1000
The characters of
name
andtyped
are lowercase letters.
给定name和typed两个字符串,问typed是否由name中每个字符出现一次或数次拼接而成。两个指针i, j分别指向name和typed的起始。匹配时就一起往前走,不同时检查typed[j]是否和typed[j-1]相同,相同则意味着是重复,向前移动j,否则不匹配。
代码参考了lee251。
Last updated
Was this helpful?