28. Implement strStr()
2016-06-27 09:55
288 查看
题目:https://leetcode.com/problems/implement-strstr/
代码:
代码:
public c b0f1 lass Solution { public int strStr(String haystack, String needle) { if(needle.length()>haystack.length()) return -1; return haystack.indexOf(needle); } } 用String的自带函数 1ms ======================= public class Solution { public int strStr(String haystack, String needle) { if(needle.length()>haystack.length()) return -1; int lengthh = haystack.length(); int lengthn = needle.length(); int index=0,i,j; while(lengthh>=lengthn) { i=0; j = index; int flag = 0; while(i<lengthn) { if(haystack.charAt(j)!=needle.charAt(i)) { flag = 1; break; } i++;j++; } if(flag == 0) return index; else { index++;lengthh--; } } return -1; } } 4ms
相关文章推荐
- 计算字节数
- ubuntu下纯字符界面下访问中文乱码解决
- java抓取网页源代码《转载》
- JAVA WordVec 的一个实现
- mybatis配置文件SqlMapConfig.xml
- android设计的布局在阿拉伯语下界面错乱的解决方法
- 贩妖记 > 第五十五章,时冰的挑衅
- FreeMarker语法解析
- HTML5 canvas基本绘图之填充样式实现
- poj2503
- X64下MmIsAddressValid的逆向及内存寻址解析
- 冒泡排序法
- HTC Vive 体验的折腾经历
- 日常小结-Schema简介
- [100] Same Tree
- 贩妖记 > 第五十五章,时冰的挑衅
- Tencent编程题-2016
- Servlet 与 CGI 的比较
- 太阳的后裔
- 使用CSS绘制基础的对话框图案的代码示例