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 ...
随机推荐
- css 页面滚动 多背景固定不动
经常看到一些网站,滚动页面但是背景图不会跟着滚动,好像一直固定在浏览器窗口,感觉挺酷的,哇哦 ~ ~ 原来都是 background-attachment 这位大兄弟的功劳 background-at ...
- Web设计精髓(转)
作者:zhouwenqi 地址:http://www.zhouwenqi.com/blog/board_43.html 这篇文章说实际问题的,所以不多强调,下面是我总结的一些比较突出的细节问题,而且 ...
- java8 四大核心函数式接口Function、Consumer、Supplier、Predicate(转载)
Function<T, R> T:入参类型,R:出参类型 调用方法:R apply(T t); 定义函数示例:Function<Integer, Integer> func = ...
- Python 多任务(线程) day2 (2)
同步 1.概念 :同步就是协同步调,按预定的先后次序运行 互斥锁 当多个线程几乎同时修改某一共享数据的时候,需要运行同步控制,最简单的同步机制是引入互斥锁.某个线程要更改共享数据时,先将其锁定,此时资 ...
- C#中的@和$ 占位符
c#中@的三种用法: 1.忽略转移字符 string str = "C:\\windows\\system32"; string str = @"C:\windows\s ...
- Servlet继承体系结构
Servlet如何只定义1个service方法,其它的方法按需求设置 Servlet——接口 ↑继承 GenericServlet——抽象类 ↑继承 HttpServlet——抽象类:推荐使用 Gen ...
- 第十七篇 Linux下常用命令汇总
- Linux下调试caffe
参考博客:https://blog.csdn.net/xiaoyezi_1834/article/details/50724875 使用Anjuta 我使用的是ubuntu18.04,安装命令: su ...
- EVE无法安装vim
有些时候,由于一些错误的操作,可能导致vim无法使用,例如如下情况: root@eve-ng:~# vim /etc/profile-bash: vim: command not found 此时,一 ...
- Intellij Idea2019版本激活,目前可以激活到2089,解决失效问题(非商业用途)
目录 Intellij Idea2019版本激活,目测可以激活到2089!! 前言-此教程仅用作个人学习,请勿用于商业获利,造成后果自负!!! 步骤(直接激活新下载的) 成功 注意(不想重新下载的小伙 ...