代码实现:
int strStr(char *haystack, char *needle) { int i, j; for (i = 0; i < strlen(haystack); i++) { for (j = 0; j < strlen(needle); j++) { if (haystack[i + j] != needle[j]) { break; } } if (j == strlen(needle)) { return i; } } return -1; }
代码实现:
int strStr(char *haystack, char *needle) { int i, j; for (i = 0; i < strlen(haystack); i++) { for (j = 0; j < strlen(needle); j++) { if (haystack[i + j] != needle[j]) { break; } } if (j == strlen(needle)) { return i; } } return -1; }