Implement strStr().

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

就是在字符串haystack中找到needle 的位置。。。

class Solution {
public:int strStr(string haystack, string needle) {int m = haystack.size();int n = needle.size();for(int i = 0; i <= m-n; i ++){int j;for(j = 0; j < n; j ++){if(haystack[i+j] != needle[j])break;}if(j == n)return i;}return -1;}
};
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int strstr(string, string);
int main()
{string a = "asdfghjklzxcvb";string b = "lzxcvb";cout << strstr(a, b);system("pause");return 0;
}int strstr(string a, string b)
{int len1 = a.size();int len2 = b.size();if (len1 < len2)return -1;int j;for (int i = 0; i < len1; i++){for (j = 0; j < len2; j++){if (a[i + j] != b[j])break;}if (j == len2)return i;}return -1;
}

还有KMP算法  还不懂呢

Implement strStr()相关推荐

  1. Leetcode: Implement strStr()

    Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needl ...

  2. LeetCode集锦(十) - 第28题 Implement StrStr

    LeetCode集锦(十) - 第28题 Implement StrStr 问题 Implement strStr().Return the index of the first occurrence ...

  3. LeetCode - 28. Implement strStr()

    28. Implement strStr() Problem's Link -------------------------------------------------------------- ...

  4. 【LeetCode从零单排】No28 Implement strStr()

    题目 Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if nee ...

  5. Leet Code OJ 28. Implement strStr() [Difficulty: Easy]

    题目: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if ne ...

  6. leetCode 28. Implement strStr() 字符串

    28. Implement strStr() Implement strStr(). Returns the index of the first occurrence of needle in ha ...

  7. 【Leetcode】【Easy】Implement strStr()

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  8. LeetCode - Easy - 28. Implement strStr()

    Topic Two Pointers, String Description https://leetcode.com/problems/implement-strstr/ Implement str ...

  9. Leetcode | Implement strStr()

    Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if need ...

最新文章

  1. python开发函数进阶:递归函数
  2. 让计算机“拥抱”常识
  3. 也议MySQL中隐式转换
  4. 手动编写第一个javaWEB文件
  5. 网站结构优化——不能忽视的优化重点
  6. 获取class文件对象三种方式
  7. 电脑删除快捷键_可能是知乎最有用的 Windows 快捷键学习指南。
  8. python从图片里提取主要颜色
  9. php显示doc文件乱码,如何解决php doc 乱码问题
  10. 如何让DataGrid能够在客户端点击某一行的任意位置,而触发服务端的事件(Asp.net)...
  11. java if经典程序_java经典程序(11-20)
  12. Android逆向笔记-IDA Pro动态调试Android程序(真机)
  13. python编程从入门到实践pdf_Python编程入门研读笔记(二)
  14. 7、Cocos2dx 3.0游戏开发找小三之3.0版本号的代码风格
  15. 种草笔记App放话:要让一万创作者月入过万
  16. Linux安装redis和部署
  17. jQuery特效:实现简易轮播图
  18. matlab编程螺旋oam,一种多模态OAM涡旋电磁波微带阵列天线制造技术
  19. 图片太大时不会出现横向滚动条
  20. 一篇文章带你搞定 SpringBoot 配合 SpringSecurity 实现自动登录功能

热门文章

  1. Android驱动中的Kconfig文件与Makefile文件
  2. S3C6410的Bootloader的两个阶段BL1和BL2编译相关学习
  3. WINCE基于CH7024实现TV OUT (VGA)功能
  4. python自动测试e_python实现hive自动化测试
  5. 写一个函数返回参数二进制中 1 的个数
  6. 第18章 类加载机制与反射
  7. SQL Server 2005系列教学(14) 用户管理
  8. 记录自定义的代码片段位置
  9. const 的学习(转载)
  10. 【IM】关于条件随机场CRF的理解