Implement strStr().

Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

Solution: 

 class Solution {
public:
int strStr(string haystack, string needle) { //runtime:4ms
int len1=haystack.size(), len2=needle.size();
for(int i=;i<=len1-len2;i++)
{
int j=;
for(;j<len2;j++){
if(haystack[i+j]!=needle[j])break;
}
if(j==len2)return i;
}
return -;
}
};

【LeetCode】28 - Implement strStr()的更多相关文章

  1. 【LeetCode】28. Implement strStr() 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 find函数 遍历+切片 日期 题目地址:https ...

  2. 【LeetCode】28. Implement strStr() (2 solutions)

    Implement strStr() Implement strStr(). Returns a pointer to the first occurrence of needle in haysta ...

  3. 【一天一道LeetCode】#28. Implement strStr()

    一天一道LeetCode系列 (一)题目 Implement strStr(). Returns the index of the first occurrence of needle in hays ...

  4. 【LeetCode】028. Implement strStr()

    Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...

  5. 【LeetCode】28. 实现 strStr()

    28. 实现 strStr() 知识点:字符串:KMP算法 题目描述 实现 strStr() 函数. 给你两个字符串 haystack 和 needle ,请你在 haystack 字符串中找出 ne ...

  6. [Leetcode][Python]28: Implement strStr()

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 28: Implement strStr()https://oj.leetco ...

  7. C# 写 LeetCode easy #28 Implement strStr()

    28.Implement strStr() Implement strStr(). Return the index of the first occurrence of needle in hays ...

  8. 【leetcode❤python】 28. Implement strStr()

    #-*- coding: UTF-8 -*- #题意:大海捞刀,在长字符串中找出短字符串#AC源码:滑动窗口双指针的方法class Solution(object):    def strStr(se ...

  9. 【LeetCode】232. Implement Queue using Stacks 解题报告(Python & Java)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Python解法 Java解法 日期 [LeetCo ...

随机推荐

  1. struts2与struts1整合,java.lang.InstantiationException, Exception occurred during processing request: null

    做了2个action,其中一个运行没有问题,另一个报错,看下面的报错信息,再看了看struts.xml,因为没有给GetBooks这个action配置actionform,所以就导致报null.下面是 ...

  2. SAP初级书籍(PM相关)

    SAP EAM设备维护系统应用及案例 SAP管理技术探秘:设备维护(全彩印刷) SAP MDM 主数据管理 SAP从入门到精通 SAP实施大全

  3. 30 个 PHP 的 Excel 处理类

    下面的 PHP Excel 处理类中,包含 Excel 读写.导入导出等相关的类,列表如下: PHP Excel Reader classes 1. Read Excel Spreadsheets u ...

  4. SQL[连载1]简介

    SQL[连载1]简介 SQL 教程 SQL 是用于访问和处理数据库的标准的计算机语言. 在本教程中,您将学到如何使用 SQL 访问和处理数据系统中的数据,这类数据库包括:MySQL.SQL Serve ...

  5. 转:CSS布局:Float布局过程与老生常谈的三栏布局

    使用CSS布局网页,那是前端的基本功了,什么两栏布局,三栏布局,那也是前端面试的基本题了.一般来说,可以使用CSSposition属性进行布局,或者使用CSSfloat属性布局.前者适合布局首页,因为 ...

  6. Linux多线程(三)(同步互斥)

    1. 线程的同步与互斥 1.1. 线程的互斥 在Posix Thread中定义了一套专门用于线程互斥的mutex函数.mutex是一种简单的加锁的方法来控制对共享资源的存取,这个互斥锁只有两种状态(上 ...

  7. jquery仿天猫商城左侧导航菜单

    之前看到有博友写了一个仿天猫商城左侧导航菜单,可惜不提供免费下载,也没有代码.以前自己也写过类似的效果,只是都是一小块一小块的,现在重新拼凑.我将一步一步的实现拼凑过程,希望对你有所帮助. Demo在 ...

  8. CodeForces Round #250 Div2

    A. The Child and Homework 注意仔细读题,WA了好多次,=_= #include <cstdio> #include <cstring> #includ ...

  9. 软件设计之UML—UML的构成[上]

    UML是一种通用的建模语言,其表达能力相当的强,不仅可以用于软件系统的建模,而且可用于业务建模以及其它非软件系统建模.UML综合了各种面向对象方法与表示法的优点,至提出之日起就受到了广泛的重视并得到了 ...

  10. 每个极客都应该知道的Linux技巧

    每个极客都应该知道的Linux技巧 2014/03/07 | 分类: IT技术 | 0 条评论 | 标签: LINUX 分享到:18 本文由 伯乐在线 - 欣仔 翻译自 TuxRadar Linux. ...