When someone drags their finger across a phone’s keyboard, we can record the letters they intersected, creating a swype path.
Given a swype path and a list of words, write a function to guess what the user is trying to type.
Example:
Inputs: "bjiojbfdsaq" ["boba", "tea", "apple"]
Output: "boba"
这道题本质上是在给定一条手机滑动输入轨迹(swype path)的情况下,从候选单词列表中找出用户最可能输入的词。常见思路是把每个候选词映射到键盘坐标,再检查它是否能对应到轨迹中出现的字母序列;如果题目要求更严格,也可以用双指针、子序列匹配或基于键盘邻接关系的遍历来判断。示例中轨迹 "bjiojbfdsaq" 对应的候选答案是 "boba",说明需要从噪声路径中提取出与目标词相符的字母顺序。
正文完