leetcode5 Implement strstr() 实现strstr函数功能

2022-12-09,,,,

  Implement strstr() 实现strstr函数功能

    whowhoha@outlook.com

Question:

Implement strstr(). Returns the index of the first occurrence of needle in haystack, or –1

if needle is not part of haystack.

int strStr(string haystack, string needle)

{

for (int i = 0; ; i++) {

for (int j = 0; ; j++) {

if (j == needle.length()) {

return i;

}

if (i + j == haystack.length()) {

return -1;

}

if (needle[j] != haystack[i + j]) {

break;

}

}

}

}

leetcode5 Implement strstr() 实现strstr函数功能的相关教程结束。

《leetcode5 Implement strstr() 实现strstr函数功能.doc》

下载本文的Word格式文档,以方便收藏与打印。