Preview:
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 };