LeetCode 28:Implement strStr()
2015-06-03 23:08
453 查看
Implement strStr().
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
实现函数strStr。代码如下:
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
实现函数strStr。代码如下:
int strStr(char* haystack, char* needle) { size_t len = strlen(haystack); if(strlen(needle) == 0) return 0; if(strcmp(haystack, needle) == 0) return 0; for(int i=0; i<len;i++){ if(haystack[i] == needle[0]){ if(strncmp(&(haystack[i]), needle, strlen(needle)) == 0) return i; } } return -1; }
相关文章推荐
- 设计模式——代理模式
- OC第五天-字典,集合,数组排序
- 图的邻接表存储
- springMVC json自动化
- 通过IP获取地区省市
- java面向对象编程
- hdu1115 Lifting the Stone(几何,求多边形重心模板题)
- iOS打电话,发短信,发邮件,打开网址
- Hibernate HelloWorld-14 批量操作
- [Hive]Hive将一行记录拆分成多行
- LeetCode 27:Remove Element
- [Asp.net 5] Logging-日志系统的基本架构(上)
- HTML第十九节(回到顶部效果)
- Android 快速开发系列 打造万能的ListView GridView 适配器
- 堆排序
- JAVA自定义异常
- 【Android开发】线程与消息处理-Handler消息传递机制之Looper
- Directory类提供的静态方法去处理目录
- zoj 1002 Fire Net(不能位于同行或同列,问最多放几个)
- Cocos2d-x的学习之旅(三)自己的 HelloWorld