LeetCode --- 1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence 解题报告

Posted 杨鑫newlfe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode --- 1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence 解题报告相关的知识,希望对你有一定的参考价值。

Given a sentence that consists of some words separated by a single space, and a searchWord, check if searchWord is a prefix of any word in sentence.

Return the index of the word in sentence (1-indexed) where searchWord is a prefix of this word. If searchWord is a prefix of more than one word, return the index of the first word (minimum index). If there is no such word return -1.

prefix of a string s is any leading contiguous substring of s.

Example 1:

Input: sentence = "i love eating burger", searchWord = "burg"
Output: 4
Explanation: "burg" is prefix of "burger" which is the 4th word in the sentence.

以上是关于LeetCode --- 1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence 解题报告的主要内容,如果未能解决你的问题,请参考以下文章