首页 > 其他 > 详细

28. Implement strStr()

时间:2016-05-17 21:18:28      阅读:257      评论:0      收藏:0      [点我收藏+]

Implement strStr().

Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

暴力

 1 int strStr(char* haystack, char* needle) {
 2     int len_hay;
 3     int len_need;
 4     int i,j;
 5     len_hay = strlen(haystack);
 6     len_need = strlen(needle);
 7     for(i = 0; i <= len_hay - len_need; i++)
 8     {
 9         for(j = 0; j < len_need; j++)
10             {
11                 if(needle[j] != haystack[i+j])
12                     break;
13             }
14         if(j == len_need)
15             return i;
16     }
17     return -1;
18     
19 }

KMP 以后写。。

28. Implement strStr()

原文:http://www.cnblogs.com/boluo007/p/5503142.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!