leetcode-algorithms-28 Implement strStr()
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-28 Implement strStr()的更多相关文章
- [Leetcode][Python]28: Implement strStr()
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 28: Implement strStr()https://oj.leetco ...
- 【一天一道LeetCode】#28. Implement strStr()
一天一道LeetCode系列 (一)题目 Implement strStr(). Returns the index of the first occurrence of needle in hays ...
- C# 写 LeetCode easy #28 Implement strStr()
28.Implement strStr() Implement strStr(). Return the index of the first occurrence of needle in hays ...
- 【LeetCode】28. Implement strStr() 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 find函数 遍历+切片 日期 题目地址:https ...
- 【LeetCode】28 - Implement strStr()
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- 【LeetCode】28. Implement strStr() (2 solutions)
Implement strStr() Implement strStr(). Returns a pointer to the first occurrence of needle in haysta ...
- 44. leetcode 28. Implement strStr()
28. Implement strStr() Implement strStr(). Returns the index of the first occurrence of needle in ha ...
- leetCode练题——28. Implement strStr()
1.题目 28. Implement strStr()——Easy Implement strStr(). Return the index of the first occurrence of ne ...
- 28. Implement strStr()【easy】
28. Implement strStr()[easy] Implement strStr(). Returns the index of the first occurrence of needle ...
- [LeetCode] 28. Implement strStr() 实现strStr()函数
Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...
随机推荐
- IAR8.11.1安装与破解教程
IAR 8.11.1的安装与破解 1.IAR的安装 (1) (2)然后选择自己的调试方式驱动(jtag与swd...) (3)选择路径,一直下一步就好 ...
- Windows下使用命令安装Python的scipy库出错的解决
平时使用Python都是在Sublime下使用,不想使用IDE.使用各种库时安装也就是使用pip安装即可.来说说今天自己遇到的一个问题:使用scipy数学库时,使用命令: pip install sc ...
- vue中click阻止事件冒泡,防止触发另一个事件
在使用el-upload组件时,在其中放置了一个删除按钮的图片. 当点击图片,本想只删除上传的视频,但是意外触发了el-upload中的事件 解决办法:用stop,结果只删除当前预览,不触发上传事件. ...
- Python 安装 lxml 插件
1.下载 lxml 地址:https://pypi.python.org/pypi/lxml/3.8.0#downloads 我用的是python 3.6,我下载了 lxml-3.8.0-cp36- ...
- Vue--获取数据
一.Jsonp抓取数据 用 npm 安装 jsonp npm install jsonp 创建 jsonp.js import originJsonp from 'jsonp' export defa ...
- mysql利用navicat导出表结构和表中数据
LZ在网上搜索了要如何导出mysql的表结构和表中数据,发现有的方法不好用 记录一下好用的方式: 用navicat打开DB链接后,点击数据库,右击选择转储SQL文件,然后选择结构和数据: 之后弹出新的 ...
- Java 中常见的各种排序算法汇总
首先,Java中自已是有排序的 说明:(1)Arrays类中的sort()使用的是“经过调优的快速排序法”;(2)比如int[],double[],char[]等基数据类型的数组,Arrays类之只是 ...
- Linux下解包/打包,压缩/解压命令
.tar 解包:tar xvf FileName.tar 打包:tar cvf fileName.tar DirName tar.gz和.tgz 解压:tar zxvf FileName.tar.zi ...
- C#6.0 语法
属性表达式 属性值初始化 public string name {get;set;} = "张三"; 函数表达式 NULL检查运算符 var aa = Created?.Date; ...
- seo中的竞价排名是什么
seo中的竞价排名是什么 一.总结 一句话总结:竞价排名的基本特点是按点击付费,推广信息出现在搜索结果中(一般是靠前的位置),如果没有被用户点击,则不收取推广费. 搜索引擎的一种推广广告的方式 1.竞 ...