leetCode练题——28. Implement strStr()
1、题目
Implement 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().
2、我的解答
用python3自带的方法 find 就可以了。。。。
# -*- coding: utf-8 -*-
# @Time : 2020/2/4 11:03
# @Author : SmartCat0929
# @Email : 1027699719@qq.com
# @Link : https://github.com/SmartCat0929
# @Site :
# @File : 28. Implement strStr().py class Solution:
def strStr(self, haystack: str, needle: str) -> int:
a=haystack.find(needle)
return a
print(Solution().strStr("happynewyear",""))
leetCode练题——28. Implement strStr()的更多相关文章
- LeetCode记录之28——Implement strStr()
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- 【leetcode❤python】 28. Implement strStr()
#-*- coding: UTF-8 -*- #题意:大海捞刀,在长字符串中找出短字符串#AC源码:滑动窗口双指针的方法class Solution(object): def strStr(se ...
- [Leetcode][Python]28: Implement strStr()
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 28: Implement strStr()https://oj.leetco ...
- 44. leetcode 28. Implement strStr()
28. Implement strStr() Implement strStr(). Returns the index of the first occurrence of needle in ha ...
- 28. Implement strStr()【easy】
28. Implement strStr()[easy] Implement strStr(). Returns the index of the first occurrence of needle ...
- LeetCode专题-Python实现之第28题: Implement strStr()
导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始 ...
- [LeetCode] 28. Implement strStr() 实现strStr()函数
Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...
- 【LeetCode】28. Implement strStr() 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 find函数 遍历+切片 日期 题目地址:https ...
- 【一天一道LeetCode】#28. Implement strStr()
一天一道LeetCode系列 (一)题目 Implement strStr(). Returns the index of the first occurrence of needle in hays ...
随机推荐
- Git 时光穿梭机
git log 提交日志 git reflog 命令日志 git status 查看状态 管理修改 git diff 工作区与暂存区 git diff master 工作区与版本库 git diff ...
- C#中Dictionary的实现简述
更详细的解析可以查看这篇文章:https://blog.csdn.net/zhaoguanghui2012/article/details/88105715 简要描述就是通过桶Buckets与Entr ...
- array.find()方法
//array.find(function(currentValue, index, arr),thisValue) 方法说明 let tempArray = [ {"key":1 ...
- ubuntu18.04双卡机安装ubidia驱动遇到的坑
在ubuntu 18的软件更新中选择英伟达驱动进行安装,输入nvidia-smi总是提示缺少驱动,未驱动之类的报错. 何解? 最初以为安装系统的问题,重装ubuntu也未果. 最后查了很多资料,找到一 ...
- flutter_html 和 WebView 解析html 和 build.gradle源码
一.flutter_html 涉及的 api 接口: http://www.phonegap100.com/appapi.php?a=getPortalArticle&aid=20 二.Flu ...
- D. Easy Problem dp(有衔接关系的dp(类似于分类讨论) )
D. Easy Problem dp(有衔接关系的dp(类似于分类讨论) ) 题意 给出一个串 给出删除每一个字符的代价问使得串里面没有hard的子序列需要付出的最小代价(子序列不连续也行) 思路 要 ...
- DFA 简易正则表达式匹配
一个只能匹配非常简单的(字母 . + *)共 4 种状态的正则表达式语法的自动机(注意,仅限 DFA,没考虑 NFA): 好久之前写的了,记得有个 bug 一直没解决... #include < ...
- IntelliJ IDEA 2017.3尚硅谷-----设置自动编译
- HDU 3823 Prime Friend(线性欧拉筛+打表)
Besides the ordinary Boy Friend and Girl Friend, here we define a more academic kind of friend: Prim ...
- Model&Form&ModelForm拾遗
Model&Form&ModelForm拾遗 一.Model&Form&ModelForm Model:用于用户请求数据的验证(针对性弱),但有强大的数据库操作 For ...