28. Implement strStr()
来源:互联网 发布:飞飞cms下载 编辑:程序博客网 时间:2024/05/16 17:47
class Solution {public: int strStr(string haystack, string needle) { int len1 = haystack.size(); int len2 = needle.size(); int i = 0 ; int index; //当两个序列的长度都是0的情况,就是零位置匹配。 if(len1 == 0 && len2 == 0 ){ return 0; }//当needle为0,haystack不为0则返回位置0。 if(len1 != 0 && len2 ==0){ return 0; } for(int i = 0 ; i < len1 -len2 + 1 ; i++ ){ for(int j = 0 ; j < len2 ; j++){ if(haystack[i+j] != needle[j]){ break; } else if(j == len2 -1){ return i; }else{ continue; } } } return -1; }};
这个题目类似KMP但是不是KMP。
0 0
- [LeetCode]28.Implement strStr()
- LeetCode --- 28. Implement strStr()
- LeetCode 28.Implement strStr()
- [Leetcode] 28. Implement strStr()
- 28. Implement strStr()
- 【leetcode】28. Implement strStr()
- [leetcode] 28.Implement strStr()
- Leetcode-28.Implement strStr()
- 28. Implement strStr()
- 28. Implement strStr()
- 28. Implement strStr()
- 28. Implement strStr() LeetCode
- 28. Implement strStr()
- leetcode 28. Implement strStr()
- [LeetCode]28. Implement strStr()
- 28. Implement strStr()
- 28. Implement strStr()
- 28. Implement strStr()
- Spring BeanFactoryPostProcessor和BeanPostProcessor的关系
- Linux学习笔记-001
- Job aborted due to stage failure: Total size of serialized results of 31 tasks (1043.8 MB) is bigger
- UVA 12186 树上dp入门
- 【二进制、字符串】UVA
- 28. Implement strStr()
- 决策树算法优化(三)
- python
- TypeError: unsupported operand type(s) for +: 'int' and 'str'
- 剑指offer——旋转数组的最小数字______
- Pytorch入门学习(三)---- NN包的使用
- java入门之超入门
- path-sum-ii
- 初步搭建Unity SteamVR开发环境