Implement strStr()
2015-07-03 18:51
429 查看
称号
Implement strStr().
Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.
方法
仅仅须要遍历一遍就可以。
public String strStr(String haystack, String needle) { int lenH = haystack.length(); int lenN = needle.length(); if(lenH < lenN ){ return null; } for(int i = 0; i < lenH - lenN + 1; i ++){ int j = 0; while(j < lenN){ if(haystack.charAt(i + j) != needle.charAt(j)){ break; } j ++; } if(j == lenN){ return haystack.substring(i, lenH); } } return null; }
相关文章推荐
- Ngx_Lua使用分享
- 正确定义Objective-C常量
- CSS透明属性详解代码
- Python笔记:_mysql常用操作
- app store上传图片显示错误:未能创建 屏幕快照
- Java 并发0
- Hibernate4.0之HibernateSessionFactory源码详解
- Android 适配器(Adapter)、观察者(Observer) 模式
- python install pycurl
- 利用CSS3实现气泡效果的教程
- leetcode | Path Sum II
- ngx映射到lua模块函数变量一览
- NYOJ 977 最大的最小公倍数
- 什么是LSP???如何看待LSP???
- 关于SIGPIPE导致的程序退出
- awk 匹配不是 pattern 的内容
- ActionBar属性和效果修改
- Nginx 与 Lua
- 九度1483 求最大最小数
- Python笔记:MySQLdb模块常用操作