Leetcode028. Implement strStr()
class Solution {
public:
int strStr(string haystack, string needle) {
if(needle.empty())return ; //needle empty
if(haystack.empty()) return -; //haystack empty
for(int i = , j = ; i+j < haystack.size();) {
if(haystack[i+j] != needle[j])i++, j = ; //no equal needle index to 0, haystack index move to next.
else j++; //equal both move to next
if(j == needle.size())return i; //thr first time find substr.
}
return -;
}
};
Leetcode028. Implement strStr()的更多相关文章
- [LeetCode] Implement strStr() 实现strStr()函数
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- 28. Implement strStr()
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- Leetcode 详解(Implement strstr)
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- [leetcode 27]Implement strStr()
1 题目: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if ...
- Leetcode #28. Implement strStr()
Brute Force算法,时间复杂度 O(mn) def strStr(haystack, needle): m = len(haystack) n = len(needle) if n == 0: ...
- 【leetcode】Implement strStr() (easy)
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- [LeetCode] Implement strStr()
Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if need ...
- Implement strStr()
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- Implement strStr() [LeetCode]
Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if need ...
随机推荐
- Linux使用笔记: 定制core dump文件的文件名
在开发过程中,当一个Linux程序异常退出时,我们可以通过core文件来分析它异常的详细原因.缺省情况下,Linux在程序异常时不产生core文件,要想让程序异常退出时产生core dump文件,需要 ...
- AP_AP系列 - 付款管理分析(案例)
2014-07-08 Created By BaoXinjian 一.摘要 1. 付款 2. 发票付款概述 3. 使用发票工作台付款 4. 使用付款管理器付款 5. 银行账户模型 二.流程分析 1. ...
- POJ 1066 Treasure Hunt(计算几何)
题意:给出一个100*100的正方形区域,通过若干连接区域边界的线段将正方形区域分割为多个不规则多边形小区域,然后给出宝藏位置,要求从区域外部开辟到宝藏所在位置的一条路径,使得开辟路径所需要打通的墙壁 ...
- alpha融合
//alpha融合 //作者:sandy //时间:2015-10-6 //将一只狗的头像融合在蜗牛头上 #include <cv.h> #include <highgui.h> ...
- xhprof 安装使用
1.安装扩展 windows下把 xhprof.dll 放到extensions目录下 修改配置文件 [xhprof] extension=xhprof.so; ; directory used by ...
- Condition的优点
那么引入本篇的主角,Condition,Condition 将 Object 监视器方法(wait.notify 和 notifyAll)分解成截然不同的对象,以便通过将这些对象与任意 Lock 实现 ...
- GDI+ 中发生一般性错误。
GDI+ 中发生一般性错误. “/wechat”应用程序中的服务器错误. GDI+ 中发生一般性错误. 说明: 执行当前 Web 请求期间,出现未经处理的异常.请检查堆栈跟踪信息,以了解有关该错误以及 ...
- jquery树形菜单完整代码
本实例实现了树形的动态菜单,兼容IE8,火狐,Chrome等浏览器.使用了jQuery的toggle() 方法.效果和代码如下: <!DOCTYPE html PUBLIC "-//W ...
- 漫谈刑事辩护 z
各位律师,各位助理: 大家好!今天的律师沙龙由我来给大家谈一谈刑事辩护方面的问题.这次我谈的,主要是我这么多年来办理刑事案件,从事刑事辩护中的一些体会. 刑事辩护,大家最关心的莫过于收费问题了.我认为 ...
- [AIR] Screen 的应用
Screen 类提供此应用程序的可用显示屏幕的相关信息. 屏幕是位于可能更大的“虚拟桌面”内的独立桌面区域.虚拟桌面的原点是操作系统指定的主屏幕的左上角.因此,个别显示屏幕范围的坐标可能是负数.虚拟桌 ...