28. Implement strStr()
2016-02-24 09:04
218 查看
最简单的方法,暴力找
bug记录:
1.第16行,错写成j == needle.length()-1,但是其实如果匹配,那么12行已经进行过j++此时应该是j == needle.length()
public int strStr(String haystack, String needle) { if(needle == null || needle.length() == 0) { return 0; } if(haystack.length() < needle.length()) { return -1; } for(int i = 0; i <= haystack.length()-needle.length(); i++) {//需要<= int j = 0; while(j < needle.length()) { if(haystack.charAt(i+j) == needle.charAt(j)) { j++; } else { break; } if(j == needle.length()) { return i; } } } return -1; }
bug记录:
1.第16行,错写成j == needle.length()-1,但是其实如果匹配,那么12行已经进行过j++此时应该是j == needle.length()
相关文章推荐
- 详解Android TableLayout表格布局
- hdu 1864 最大报销额
- KVC,KVO,NSNotification总结
- Laravel报class does not exist的一种可能原因及其解决办法
- IOS开发中的微信支付功能
- ROW_NUMBER
- jsp页面传递数组参数到后台
- 静态库和动态库
- 【SDOI2013】项链
- BMP 转 YUV (BMP2YUV)+ YUV 转RGB
- 滴滴快车奖励政策,高峰奖励,翻倍奖励,按成交率,指派单数分级(2月24日)
- Qemu之Network Device全虚拟方案二:虚拟网卡的创建
- vim配置
- iOS 缓存机制
- 项目记录22-- tolua基于lua框架事件派发
- JavaScript鼠标拖拽特效及相关问题总结
- 九度题目1018(Hash)
- DPM(voc-release5) Matlab模型文件 Mat转XML
- matlab 输出汉字,解决英语系统乱码问题
- #define+do{} while(0)+peeror的思考