1 static int wing=[]()
 2 {
 3     std::ios::sync_with_stdio(false);
 4     cin.tie(NULL);
 5     return 0;
 6 }();
 7 
 8 class Solution 
 9 {
10 public:
11     int strStr(string haystack, string needle) 
12     {
13         int mlen=haystack.length();
14         int slen=needle.length();
15         if(slen==0)
16             return 0;
17         for(int i=0;i<mlen-slen+1;i++)
18         {
19             int j=0;
20             for(;j<slen;j++)
21             {
22                 if(haystack[i+j]!=needle[j])
23                     break;
24             }
25             if(j==slen)
26                 return i;
27         }
28         return -1;
29     }
30 };

基本算是暴力解法,问题不大。

posted on 2018-04-16 13:38  高数考了59  阅读(93)  评论(0)    收藏  举报