设为首页 加入收藏

TOP

28. Implement strStr()
2017-10-12 17:41:09 】 浏览:2363
Tags:28. Implement strStr

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 以后写。。

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Single Number II 下一篇素数对猜想

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目