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. SQL SERVER ->> Columnstore Index

    谈到Columnstore index就不得不提SQL SERVER的压缩技术了.Columnstore就是用到了SQL SERVER的压缩技术.Columnstore又分Columnstore和Co ...

  2. USACO Section 3.1: Score Inflation

    完全背包问题 /* ID: yingzho1 LANG: C++ TASK: inflate */ #include <iostream> #include <fstream> ...

  3. URAL 1069 Prufer Code 优先队列

    记录每个节点的出度,叶子节点出度为0,每删掉一个叶子,度数-1,如果一个节点的出度变成0,那么它变成新的叶子. 先把所有叶子放到优先队列中. 从左往右遍历给定序列,对于root[i],每次取出叶子中编 ...

  4. Pycharm连接gitlab

    一.从gitlab上clone代码到本地pycharm (一).gitlab上找到创建项目的连接地址,分两种: 1. http连接方式: http://10.22.1.72/derekchen/cxg ...

  5. Tmall发送码asp验证sing(自有码开发)

    <%''查询通知应答类'============================================================================'api说明:'g ...

  6. Photoshop图层混合模式计算公式大全(转)

    混合模式可以将两个图层的色彩值紧密结合在一起,从而创造出大量的效果.在这些效果的背后实际是一些简单的数学公式在起作用.下面我将介绍photoshop cs2中所有混合模式的数学计算公式.另外还介绍了不 ...

  7. 监控tomcat性能

    tomcat经常被用作中间件,也有直接作WEB的,自带的工具不是很给力,推荐以下的办法 工具/原料 javamelody 方法/步骤   下载 javamelody.jar和 jrobin-x.jar ...

  8. VS2015新功能

    今天有幸参加了微软的 Visual Studio Dev Day,趁还没有忘记今天的学习内容. 先把这些内容记录下来,如果有其他人也参加此次交流活动,请补充完善. VS2015新功能 1,Roslyn ...

  9. Intellij IDEA13 创建多模块Maven项目

    目标:构建一个类似于如下图所示的这种结构的Maven项目. 首先,需要选中“File”——>“New Project”如下图所示 选中“Maven”,设置项目名称与项目构建地址,点击“Next” ...

  10. 【转载】Mysql binlog relaylog 日志迁移

    背景:   默认情况下,mysql的数据.binlog.relaylog都是保存在同一个磁盘上,路径根据每个人的设置不一. 当mysql数据库中数据或日志增长很快时,磁盘可能面临空间不够或者IO性能跟 ...