题解 | #牛群的信息传递#
牛群的信息传递
https://www.nowcoder.com/practice/0130cb88968a441b9eedbc103466d2bf
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param message string字符串
* @param keyword string字符串
* @return int整型
*/
int findKeyword(char* message, char* keyword ) {
// write code here
int len = strlen(message);
int len1 =strlen(keyword);
int i = 0;
int j = 0;
while(i < len){
if(message[i] == keyword[j]){
i++;
j++;
if(j == len1){
return i-j;
}
}
else{
i = i - j + 1;
j = 0;
}
}
return -1;
}

阿里巴巴公司氛围 653人发布