描述
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:
1 | Input: name = "alex", typed = "aaleex" |
Example 2:
1 | Input: name = "saeed", typed = "ssaaedd" |
Example 3:
1 | Input: name = "leelee", typed = "lleeelee" |
Example 4:
1 | Input: name = "laiden", typed = "laiden" |
Note:
分析
利用双指针解决这个问题,遍历 typed 的指针走得更快,如果 typed 遍历完了,name 还没有遍历完,则返回 false。
解决方案1(Java)
1 | class Solution { |