Implement strStr().

Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

额,当然我用的就是暴力搜索来,没用到KMP之类的算法,有时间再来补上辣,代码如下:

 class Solution {
public:
int strStr(string haystack, string needle) {
if(!needle.size()) return ;
if(haystack.size() < needle.size()) return -;
for(int i = ; i <= haystack.size() - needle.size(); ++i){
int start = i;
for(int j = ; j < needle.size() && start < haystack.size() && haystack[start] == needle[j]; ++j, ++start){
}
if(start-i == needle.size()) return i;
}
return -;
}
};

最新文章

  1. flask-whooshalchemy需要注意的一点
  2. brew
  3. Java-计划存储
  4. [moka同学代码]PHP初级知识:上传文件源码
  5. C#:控制WinForm界面的显示
  6. 转载 网页打印时设置A4大小
  7. DVRF:路由器漏洞练习靶机 Damn Vulnerable Router Firmware
  8. poj2367 拓扑序
  9. JAVA:借用OpenOffice将上传的Word文档转换成Html格式
  10. 基于jQuery带图标的多级下拉菜单
  11. C++服务器设计(六):设备连接的生命周期管理
  12. C#反射 入门学习 01
  13. MySQL服务相关
  14. 腾讯云中ssL证书的配置安装
  15. 生成ssh公钥
  16. 洛谷3084 [USACO13OPEN]照片Photo
  17. Flask初级(三)flash使用模板
  18. Luogu 3245 大数
  19. Caused by: java.lang.IllegalStateException: Expected raw type form of org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$Match
  20. 关于strip(切割)和 split(分开) 的区别

热门文章

  1. url get与post 请求长度限制
  2. AJAX跨域问题解决方法(4)——调用方解决跨域
  3. fastdfs安装与配置
  4. Elasticsearch+Kibana+Logstash安装
  5. 20145231熊梓宏 《网络对抗》 实验9 Web安全基础实践
  6. Jenkins 集成Maven打包SpringBoot项目并自动部署到Tomcat服务器
  7. openwrt下如何只编译linux内核
  8. 设置CentOS7虚拟机使用静态IP上网
  9. windchill系统安装大概步骤
  10. LaTeX模板 - FORMCM