Preview:

1. Implement strStr()

O(m*n):

 1 class Solution
 2 {
 3 public:
 4     int strStr(string haystack,string needle)
 5     {
 6         for(int i=0;i<=int(haystack.size()-needle.size());i++)
 7         {
 8             int j;
 9             for(j=0;j<needle.size();j++)
10             {
11                 if(haystack[i+j]!=needle[j])
12                     break;
13             }
14             if(j==needle.size())
15                 return i;
16         }
17         return -1;
18     }
19 };
View Code

相关文章:

  • 2022-01-01
  • 2021-07-14
  • 2021-12-23
  • 2021-11-30
  • 2021-10-31
  • 2021-08-30
  • 2022-01-28
猜你喜欢
  • 2021-08-04
  • 2022-12-23
  • 2022-12-23
  • 2021-04-13
  • 2021-08-03
  • 2021-11-09
相关资源
相似解决方案