【LeetCode】28 - Implement strStr()
Implement strStr().
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
Solution:
class Solution {
public:
int strStr(string haystack, string needle) { //runtime:4ms
int len1=haystack.size(), len2=needle.size();
for(int i=;i<=len1-len2;i++)
{
int j=;
for(;j<len2;j++){
if(haystack[i+j]!=needle[j])break;
}
if(j==len2)return i;
}
return -;
}
};
【LeetCode】28 - Implement strStr()的更多相关文章
- 【LeetCode】28. Implement strStr() 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 find函数 遍历+切片 日期 题目地址:https ...
- 【LeetCode】28. Implement strStr() (2 solutions)
Implement strStr() Implement strStr(). Returns a pointer to the first occurrence of needle in haysta ...
- 【一天一道LeetCode】#28. Implement strStr()
一天一道LeetCode系列 (一)题目 Implement strStr(). Returns the index of the first occurrence of needle in hays ...
- 【LeetCode】028. Implement strStr()
Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...
- 【LeetCode】28. 实现 strStr()
28. 实现 strStr() 知识点:字符串:KMP算法 题目描述 实现 strStr() 函数. 给你两个字符串 haystack 和 needle ,请你在 haystack 字符串中找出 ne ...
- [Leetcode][Python]28: Implement strStr()
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 28: Implement strStr()https://oj.leetco ...
- C# 写 LeetCode easy #28 Implement strStr()
28.Implement strStr() Implement strStr(). Return the index of the first occurrence of needle in hays ...
- 【leetcode❤python】 28. Implement strStr()
#-*- coding: UTF-8 -*- #题意:大海捞刀,在长字符串中找出短字符串#AC源码:滑动窗口双指针的方法class Solution(object): def strStr(se ...
- 【LeetCode】232. Implement Queue using Stacks 解题报告(Python & Java)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Python解法 Java解法 日期 [LeetCo ...
随机推荐
- Index & Statistics ->> Rebuild Index会不会覆盖原先Index的WITH选项设置
昨天因为工作中遇到要对某个数据库的表通通启用data_compression,突然有个念头,就是如果我当初用"ALTER INDEX XXX ON YYY REBUILD WITH (DAT ...
- java Comparable和Comaprator的对比
Comparable使一个class具备不同实例间进行比较的行为.这些对象的集合,可作为Collections.sort或Arrays.sort的参数 Comparator可以看成一种算法的实现,将算 ...
- 我 Git 命令列表 (1)【转】
转自:http://www.microsofttranslator.com/bv.aspx?from=en&to=zh-CHS&a=http%3A%2F%2Fvincenttam.gi ...
- Android eMMC Booting
Android eMMC Booting Contents [hide] 1 eMMC binaries 1.1 Creating the GPT table 1.2 Modifying .IMG F ...
- 在tomcat目录下启动tomcat,可以正常访问tomcat主页,然在在eclipse中集成了tomcat却访问不了tomcat主页,却能访问发布的项目
tomcat server在eclipse中正常配置了,在eclipse建tomcat服务是在server 视图那里new server建立的,但把项目部署到tomcat后却发现tomcat主页报40 ...
- UVa 12174 (滑动窗口) Shuffle
首先预处理一下以每个数为结尾的前s个数是否能构成一个1~s的排列. 可以用cnt数组来记录每个数出现的次数和用一个变量记录一共有多少个不同的数出现. 然后枚举每种可能的情况,也就是枚举第一首歌会出现的 ...
- mysql 存储过程 事务; mysql的事务中包含一个存储过程
在asp.net结合mysql的开发中,我平时用到的事务处理是 使用 TransactionOptions 来进行处理 TransactionOptions transactionOption = ...
- mysql-主从复制(一)
1)用户授权 grant all privileges on share.* to 'abc'@'192.168.1.105' identified by '123456' 2)开启mysql的bin ...
- BZOJ 4631 踩气球
BZOJ上内存小了会WA.... 线段树上挂链表. #include<iostream> #include<cstdio> #include<cstring> #i ...
- fcntl()功能 详解
fcntl()函数可以改变已打开文件的性质 <pre lang="c" escaped="true"> #include <unistd.h& ...