Implement strStr()
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()相关推荐
- Leetcode: Implement strStr()
Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needl ...
- LeetCode集锦(十) - 第28题 Implement StrStr
LeetCode集锦(十) - 第28题 Implement StrStr 问题 Implement strStr().Return the index of the first occurrence ...
- LeetCode - 28. Implement strStr()
28. Implement strStr() Problem's Link -------------------------------------------------------------- ...
- 【LeetCode从零单排】No28 Implement strStr()
题目 Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if nee ...
- 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 ...
- leetCode 28. Implement strStr() 字符串
28. Implement strStr() Implement strStr(). Returns the index of the first occurrence of needle in ha ...
- 【Leetcode】【Easy】Implement strStr()
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- LeetCode - Easy - 28. Implement strStr()
Topic Two Pointers, String Description https://leetcode.com/problems/implement-strstr/ Implement str ...
- Leetcode | Implement strStr()
Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if need ...
最新文章
- python开发函数进阶:递归函数
- 让计算机“拥抱”常识
- 也议MySQL中隐式转换
- 手动编写第一个javaWEB文件
- 网站结构优化——不能忽视的优化重点
- 获取class文件对象三种方式
- 电脑删除快捷键_可能是知乎最有用的 Windows 快捷键学习指南。
- python从图片里提取主要颜色
- php显示doc文件乱码,如何解决php doc 乱码问题
- 如何让DataGrid能够在客户端点击某一行的任意位置,而触发服务端的事件(Asp.net)...
- java if经典程序_java经典程序(11-20)
- Android逆向笔记-IDA Pro动态调试Android程序(真机)
- python编程从入门到实践pdf_Python编程入门研读笔记(二)
- 7、Cocos2dx 3.0游戏开发找小三之3.0版本号的代码风格
- 种草笔记App放话:要让一万创作者月入过万
- Linux安装redis和部署
- jQuery特效:实现简易轮播图
- matlab编程螺旋oam,一种多模态OAM涡旋电磁波微带阵列天线制造技术
- 图片太大时不会出现横向滚动条
- 一篇文章带你搞定 SpringBoot 配合 SpringSecurity 实现自动登录功能