diff options
Diffstat (limited to 'implement_strstr.cpp')
-rw-r--r-- | implement_strstr.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/implement_strstr.cpp b/implement_strstr.cpp new file mode 100644 index 0000000..4c888c2 --- /dev/null +++ b/implement_strstr.cpp @@ -0,0 +1,19 @@ +#include "leetcode.h" + +class Solution { +public: + int strStr(string haystack, string needle) { + int m = haystack.size(), n = needle.size(); + for (int i = 0; i <= m - n; i++) { + int j; + for (j = 0; j < n; j++) + if (haystack[i + j] != needle[j]) + break; + if (j == n) + return i; + } + return -1; + } +}; + +int main() {} |