leetcode 字符串匹配Implement strStr()
2015-08-12 13:47
423 查看
mplement strStr().
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
判断字符串needle是否在字符串haystack中,若在在返回第一次出现的下标。
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
判断字符串needle是否在字符串haystack中,若在在返回第一次出现的下标。
class Solution { public: int strStr(string haystack, string needle) { int l=needle.length(); int l1=haystack.length(); int i; for(i=0;i<l1-l+1;i++) { string haystack1; haystack1.assign(haystack.substr(i,l)); cout<<haystack1<<endl; if(haystack1.compare(needle)==0)return i; } return -1;} };
相关文章推荐
- CAS工作流程
- hdoj 4753 博弈+搜索
- 负载均衡之LVS--Shell脚本配置LVS
- android-学习笔记之按钮事件
- Android中Button事件的几种写法
- PHP_PHP操作Excel-SimpleExcel.php
- 深度学习( Deep Learning )软件资源列表
- jstl记录
- 【转载】什么样的测试团队才是理想的团队?
- Android SurfaceView使用
- zookeeper详解
- 制作tooltips
- 【VR】Leap Motion 官网文档 LeapRecorder (Leap记录器)
- 编译安装mod_jk on centOS
- js 点击按钮跳转 window.location.href
- Highcharts数据标签中设置时间格式
- Nginx模块开发(2)————下载文件
- 在代码中使用Autolayout (2) – intrinsicContentSize和Content Hugging Priority
- A Tutorial on android.hardware.camera2.*
- Java反射机制