Implement strStr()
来源:互联网 发布:java项目开发四个步骤 编辑:程序博客网 时间:2024/06/09 19:38
即:自己实现strstr()函数
Implement strStr().
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
解题思路:
求出两个函数的长度差值,即返回值index的取值范围
int strStr(char* haystack, char* needle) {
int len1 = strlen(haystack);int len2 = strlen(needle);int len = len1 - len2;int i, j;for (i = 0; i <= len; i++){ for (j = 0; j < len2; j++) { if (needle[j] != haystack[i+j]) { break; } } if (j == len2) { return i; }}return -1;
}
0 0
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- 小感悟
- Density of Power Network
- Android Launcher隐藏指定应用的启动图标
- NYOJ 596 谁是最好的Coder
- spring容器加载完毕做一件事情(利用ContextRefreshedEvent事件)
- Implement strStr()
- 精通Hibernate——Hibernate核心接口
- iOS编程:学习篇(八)
- CSS 之float
- 股票学习(技术04)
- minisat 安装指南
- *HDU 5305 - Friends (DFS + 剪枝)
- Objective-C学习笔记(十七)——成员变量和属性详解
- SUSE Linux源码编译安装MySQL 5.6