日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Implement strStr()

發布時間:2025/4/16 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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()的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。