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. 网页中Div的打印

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  2. linux系统下各类软件安装笔记

    安装环境: linux版本:ubuntu 16.04 安装python3.6 sudo add-apt-repository ppa:jonathonf/python-3.6              ...

  3. 遍历一个可迭代对象中的所有元素,但是却不想使用for循环

    def manual_iter(): with open('/etc/passwd') as f: try: while True: line = next(f) print(line, end='' ...

  4. python3.7.2 pip 出现locations that require TLS/SSL异常处理方法

    centos7安装python3.7.2后,运行 pip3 install tornado 会报错 [root@localhost ~]# pip3 install tornado pip is co ...

  5. 面试题中关于String的常见操作

    题目1: 将用户输入的一段话,每个单词的首字母大写, 每个单词之间的空格调整为只有一个,遇到数字,将数字与后一个单词用下划线 "_" 进行连接 题目2:将 i @@ am @@@ ...

  6. java开发手册(阿里巴巴)——编程规约(部分)

    (一)命名风格 3. [强制]类名使用 UpperCamelCase 风格,但以下情形例外:DO / BO / DTO / VO / AO / PO / UID 等. 正例:MarcoPolo / U ...

  7. node启动服务报错Node.js Error: Cannot find module express

    在node文件夹中(M:\express-test),执行 npm install express 在使用npm安装express时,报npm WARN saveError ENOENT: no su ...

  8. 《剑指offer》第五十七题(为s的连续正数序列)

    // 面试题57(二):为s的连续正数序列 // 题目:输入一个正数s,打印出所有和为s的连续正数序列(至少含有两个数). // 例如输入15,由于1+2+3+4+5=4+5+6=7+8=15,所以结 ...

  9. ArcFace 2.0 Demo [C++]

    环境: win10(10.0.16299.0)+ VS2017 sdk版本:ArcFace v2.0 OPENCV3.43版本 x64平台Debug.Release配置都已通过编译 下载地址:http ...

  10. 使用Qpaint在图片上写文字

    开发过程中需要实现在图片上叠加文字,可以采用Qpaint在图片上写文字,然后将图片显示在上面.再将Qlabel加到Qwidget中.效果如下 //创建对象,加载图片 QPixmap pix; pix. ...