题目来源
题目描述
题目解析
class Solution {
public:
int isPrefixOfWord(string sentence, string searchWord) {
std::stringstream os(sentence);
std::string tmp;
int idx = 0;
while (os >> tmp){
idx++;
if(tmp.size() < searchWord.size()){
continue;
}
bool flag = true;
int i = 0;
while (i < searchWord.size()){
if(tmp[i] != searchWord[i]){
flag = false;
break;
}
i++;
}
if(flag){
return idx;
}
}
return -1;
}
};