28. Implement strStr()
来源:互联网 发布:淘宝拍卖车辆靠谱吗 编辑:程序博客网 时间:2024/06/05 10:29
Implement strStr().
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
class Solution {public: int strStr(string haystack, string needle) { int n = haystack.size(); int m = needle.size(); if(needle.empty()) return 0; for(int i= 0, j = 0; i < n && j < m ; ++i) { if(haystack[i] == needle[j]) { if(j == m-1) return i-j; else ++j; } else{ i -= j; j = 0; } } return -1; }};
class Solution {public: int strStr(string haystack, string needle) { return haystack.find(needle); }};
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()
- Eclipse 构建Maven项目
- 一道有意思的概率应用题
- 软考总结
- 树结构练习——判断给定森林中有多少棵树
- struts7学习-(JNDI)
- 28. Implement strStr()
- 用shell bash自动化程序
- 使用RMySQL将csv文件数据导入MySQL数据库
- Git Bash配置及Key的提交
- 2016.11.11小练习
- 9G第几天
- maven profile实现多环境打包
- 关于安卓布局优化的几点建议
- 模拟spring IOC,DI,深入理解spring IOC,DI的好处