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 ...
随机推荐
- Idea全部快捷键+自行修改快捷键
Idea常用快捷键 Tab,代码标签输入完成后,按 Tab,生成代码 Ctrl+E,最近的文件 Ctrl+X,删除行 Ctrl+D,复制行 Alt+1,快速打开或隐藏工程面板 ctrl+alt+t 快 ...
- 松软科技课堂:jQuery 语法
jQuery 语法 jQuery 语法是为 HTML 元素的选取编制的,可以对元素执行某些操作. 基础语法是:$(selector).action() 美元符号定义 jQuery 选择符(select ...
- CAN总线冲突裁决
当总线上的几个器件同时发送数据的时候,CAN总线必须决定哪个器件可以发送,而其他的器件必须等待.冲突裁决是CAN协议最重要的一个特性. 以下图为例.总线上有器件A,B,C,D.A,B,C同时发出SOF ...
- L2-1 分而治之
思路 这题的意思是,如果把这些点打掉,其他的点是否能够完全不连通. 用并查集,或者打上标记之后,判断每个点是否还能到达其他点,如果一个点可以到达其他任何点,都应该输出否. 代码 #include &l ...
- 【音乐欣赏】《Abnormalize》 - 凛として時雨
曲名:Abnormalize 作者:凛として時雨 [00:00.96]誰にも見せられないもの [00:06.44]頭の中溢れて [00:11.96]間違いさえも無い世界へ [00:17.16]迷い込ん ...
- C#对字典Dictionary 的添加,遍历,移除系列操作
C#对字典Dictionary 的添加,遍历,移除系列操作: //一.创建泛型哈希表,然后加入元素 Dictionary<string, string> oscar = new Dicti ...
- linux 下查看Tomcat的状态,以及开启停止服务命令
1.首先进入你的tomcat 的bin目录下 cd /你的安装目录/tomcat/bin 查看服务启动情况 ps -ef|grep java 此条命令具体含义 ps:将某个进程显示出来 -A 显示所有 ...
- 对象析构谈—— delete this 的使用及注意事项
this对象是必须是用 new操作符分配的(而不是用new[],也不是用placement new,也不是局部对象,也不是global对象): delete this后,不能访问该对象任何的成员变量及 ...
- 「CSP-S模拟赛」2019第三场
目录 T1 「POI2007」山峰和山谷 Ridges and Valleys 题目 考场思路(几近正解) 正解 T2 「JOI 2013 Final」 现代豪宅 题目 考场思路(正解) T3 「SC ...
- Bugku-CTF之这是一个神奇的登陆框
Day32 这是一个神奇的登陆框 http://123.206.87.240:9001/sql/ flag格式flag{}