[LeetCode] Implement strStr()
2012-11-26 20:51
435 查看
Implement strStr().
Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.
Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.
class Solution { public: char *strStr(char *haystack, char *needle) { // Start typing your C/C++ solution below // DO NOT write int main() function int hayLen = strlen(haystack); int needLen = strlen(needle); for(int i = 0; i <= hayLen - needLen; i++) { char *p = haystack + i; char *q = needle; while(*q != '\0') { if (*p != *q) break; else { p++; q++; } } if (*q == '\0') return haystack + i; } return NULL; } };
相关文章推荐
- LeetCode Implement strStr() 实现strstr()
- [Leetcode]#28 Implement strStr()
- LeetCode(28)--Implement strStr()
- 【leetcode】 Implement strStr()
- LeetCode:Implement strStr()
- Leetcode: Implement strStr()
- 【leetcode】Implement strStr()
- LeetCode (Implement strStr())
- Implement strStr() 实现strStr函数 @ LeetCode
- Leetcode: Implement strStr()
- LeetCode 28 - Implement strStr()
- LeetCode(28)Implement strStr()
- leetcode 28: Implement strStr()
- LeetCode 28 — Implement strStr()(C++ Java Python)
- LeetCode Implement strStr() 暴力法, KMP法, Boyer-Moore简易版法
- Implement strStr()_Leetcode_#28
- [LeetCode][Java] Implement strStr()
- [LeetCode]Implement strStr()
- leetcode[28]Implement strStr()
- LeetCode-Implement strStr()-字符串查找