Implement strStr().

Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.


暴力法,从haystack第一个字符开始查找needle。

代码如下:

 public class Solution {
public String strStr(String haystack, String needle) {
if(haystack == null)
return null; if(needle.length() == 0)
return haystack; int i,j = 0;
for(i = 0;i < haystack.length() - needle.length() + 1;i++){
for(j = 0;j < needle.length();j++){
if(haystack.charAt(i+j) != needle.charAt(j))
break;
}
if(j == needle.length())
return haystack.substring(i,haystack.length());
}
return null;
}
}

最新文章

  1. windows系统路径环境变量
  2. CSS盒子模型与box-sizing
  3. [问题2014S14] 解答
  4. javaWeb 使用cookie显示上次访问网站时间
  5. USACO Section 2.2: Runaround Numbers
  6. js判断checkbox是否已选
  7. Alex: 2018年对混合现实MR的展望
  8. 圆形图片 ImageView
  9. 【干货】利用MVC5+EF6搭建博客系统(三)添加Nlog日志、缓存机制(MemoryCache、RedisCache)、创建控制器父类BaseController
  10. 国产 WEB UI 框架 (收费)-- Quick UI,Mini UI
  11. Kali Day01 --- arpspoof命令进行断网攻击(ARP欺骗)
  12. 【BZOJ4259】残缺的字符串(FFT)
  13. 原生js的ajax请求
  14. Android之 看“马达”如何贯通Android系统 (从硬件设计 --&gt; 驱动 --&gt; HAL --&gt; JNI --&gt; Framework --&gt; Application)
  15. Ubuntu端口命令---查看端口占用及关闭
  16. Centos7下Yum安装PHP5.5,5.6,7.0
  17. ASP.NET 文件上传于下载
  18. CCF认证201712-2游戏
  19. 对CCLE数据库可以做的分析--转载
  20. leetcode-40-组合总和 II

热门文章

  1. The return types for the following stored procedures could not be detected
  2. java之Cookie具体解释
  3. Windows安装Redis的php扩展
  4. JQuery小结(转)
  5. nodeJS 中关于 promise 的使用
  6. Highways - poj 2485 (Prim 算法)
  7. jquery简洁遮罩插件
  8. 12 Memcached 缓存无底洞现象
  9. 【POJ-2524】Ubiquitous Religions(并查集)
  10. 读书笔记-HBase in Action-第三部分应用-(1)OpenTSDB