Implement strStr()
来源:互联网 发布:淘宝店现在还挣钱么 编辑:程序博客网 时间:2024/06/02 04:03
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;}
0 0
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Go语言中Tcp协议粘包问题处理
- 代码格式化
- openstack python api 开发
- linux下android 常用指令
- linux terminal终端插件oh-my-zsh
- Implement strStr()
- java自定义List链表
- matlab:如何把一个文件夹中的所有文件名提出来
- mac 显示隐藏 隐藏文件的命令
- leetcode:118 Pascal's Triangle-每日编程第二十四题
- 创建二叉排序树并查找值为x的节点(c语言版)
- 命名
- Android基础的sharedPreferences存储,ListView,以及httpclient,和asynchttp框架请求的使用
- QT初级错误:继承于QMainwindow的窗口需调用setCentralWidget