leetcode5 Implement strstr() 实现strstr函数功能
2016-08-06 09:02
405 查看
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;
}
}
}
}
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;
}
}
}
}
相关文章推荐
- 【LeetCode】005 Implement strStr() 函数strStr()的功能实现
- [C++]LeetCode 28: Implement strStr() (实现strStr()函数)
- 【LeetCode-面试算法经典-Java实现】【028-Implement strStr() (实现strStr()函数)】
- LeetCode 28 Implement strStr()(实现strStr()函数)
- LeetCode 28 Implement strStr() (实现找子串函数)
- [LeetCode] Implement strStr() 实现strStr()函数
- leetcode | Implement strStr() | 实现字符串查找函数
- LeetCode Implement strStr() 实现strstr()
- leetcode 28. Implement strStr() 实现strStr()函数
- 每天一道LeetCode-----KMP算法查找子串,重新实现strStr()函数
- 【leetcode KMP算法实现】Implement strStr()
- leetcode——Implement strStr() 实现字符串匹配函数(AC)
- LeetCode专题-Python实现之第28题: Implement strStr()
- leetcode 题解 || Implement strStr() 问题 (即 KMP 算法实现)
- LeetCode Implement Trie (Prefix Tree) (实现trie树3个函数:插入,查找,前缀)
- 实现c语言strstr函数功能
- 模拟实现strstr函数功能
- Implement strStr() 实现strStr函数 @ LeetCode
- [LeetCode]44. Implement strStr()实现strStr()函数
- [LeetCode] Implement strStr() 实现strStr()