leetcode-algorithms-28 Implement strStr()

mplement strStr().

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

Example 1:

Input: haystack = "hello", needle = "ll"
Output: 2

Example 2:

Input: haystack = "aaaaa", needle = "bba"
Output: -1

Clarification:

What should we return when needle is an empty string? This is a great question to ask during an interview.

For the purpose of this problem, we will return 0 when needle is an empty string. This is consistent to C's strstr() and Java's indexOf().

解法

class Solution
{
public:
int strStr(string haystack, string needle)
{
return haystack.find(needle);
}
};

链接: leetcode-algorithms 目录

leetcode-algorithms-28 Implement strStr()的更多相关文章

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

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

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

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

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

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

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

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

  5. 【LeetCode】28 - Implement strStr()

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

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

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

  7. 44. leetcode 28. Implement strStr()

    28. Implement strStr() Implement strStr(). Returns the index of the first occurrence of needle in ha ...

  8. leetCode练题——28. Implement strStr()

    1.题目 28. Implement strStr()——Easy Implement strStr(). Return the index of the first occurrence of ne ...

  9. 28. Implement strStr()【easy】

    28. Implement strStr()[easy] Implement strStr(). Returns the index of the first occurrence of needle ...

  10. [LeetCode] 28. Implement strStr() 实现strStr()函数

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

随机推荐

  1. 怎么用mybatis

    一般mybatis的用法.mapper-spring-boot-starter  + PageHelper分页插件. 1,PageHelper分页插件 . https://blog.csdn.net/ ...

  2. 4-Four-Seeing hands

      ①Several cases have been reported in Russia recently of people who can read and detect colours wit ...

  3. VHDL 数字时钟设计

    序言 这个是我在做FPGA界的HelloWorld--数字钟设计时随手写下的,再现了数字钟设计的过程 目标分析 时钟具有时分秒的显示,需6个数码管.为了减小功耗采用扫描法显示 按键设置时间,需要对按键 ...

  4. 51nod 1405 树的距离之和(dfs)

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1405 题意: 思路: 先求出所有点到根节点的距离,需要维护每棵子树的大小 ...

  5. JAVA之经典算法

    package Set.Java.algorithm; import java.util.Scanner; public class algorithm { /** * [程序1] 题目:古典问题:有 ...

  6. [从零开始搭网站二]服务器环境配置:Mac电脑连接CentOS不用每次都输入密码

    上一篇讲了如何购买服务器,并且***.看这里的第一篇文章: 从零开始搭网站 从这里开始的文章,我会默认大家都是最起码是入门级的程序员,如果你完全不懂我在说什么,那就退出好了. 作为开发人员,接下来为了 ...

  7. python shelve模块

    #coding=utf- import shelve f = shelve.open("shelve_test") f['info'] = "alex" f[, ...

  8. 数据库锁机制(以MySQL为例)

    选自:https://blog.csdn.net/aluomaidi/article/details/52460844 https://www.zhihu.com/question/51513268/ ...

  9. [jshint] 'import' is only available in ES6 (use 'esversion: 6'). (W119) 提示import等ES6语法的jshint错误的,在代码前加一行 /* jshint esversion: 6 */

    官方下载了vue的简单项目,用vscode打开main.js,代码前出现黄点,js报错了 把鼠标移至import的波浪线上,出现提示:W119 - ‘import’  is only availabl ...

  10. vue模拟后端获取数据——json-server与express

    转载自: https://blog.csdn.net/weixin_39728230/article/details/80293892 https://blog.csdn.net/lxkll/arti ...