28. Implement strStr() (String)
Implement strStr().
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
class Solution {
public:
int strStr(string haystack, string needle) {
int firstPos = ;
int i, j;
int haySize = haystack.length();
int needleSize = needle.length();
if(needleSize == ) return ;
for(i = ; i < haySize; firstPos++){
i = firstPos;
for(j = ; j < needleSize && i < haySize; j++, i++){
if(needle[j]!=haystack[i]) break;
}
if(j == needleSize) return firstPos;
}
return -;
}
};
28. Implement strStr() (String)的更多相关文章
- [Leetcode][Python]28: Implement strStr()
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 28: Implement strStr()https://oj.leetco ...
- 28. Implement strStr()【easy】
28. Implement strStr()[easy] Implement strStr(). Returns the index of the first occurrence of needle ...
- leetCode练题——28. Implement strStr()
1.题目 28. Implement strStr()——Easy Implement strStr(). Return the index of the first occurrence of ne ...
- 44. leetcode 28. Implement strStr()
28. Implement strStr() Implement strStr(). Returns the index of the first occurrence of needle in ha ...
- 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() 实现strStr()函数
Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...
- 【LeetCode】28 - Implement strStr()
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- Java [leetcode 28]Implement strStr()
题目描述: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if ...
- [LeetCode] 28. Implement strStr() 解题思路
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
随机推荐
- Centos系统更改yum源为163
Centos安装好之后,按照网上教程对yum源进行修改,但更新之后发现总是提示更新失败,到163网站上查找资源发现目前大部分网上的教程都写错地址了,呵呵 下面是正确的办法,请参考 1.进入存放源配置的 ...
- 干掉某个用户的所有进程 ---slay和kill
要杀掉指定进程,你可以: 1.sudo slay <name> 知道进程名字即可 2.kill[参数][进程号] 知道进程ID即可 用‘slay’干掉某个用户的所有进程 slay 是Ch ...
- iOS 关于时间天数星期月份的总结
#import <Foundation/Foundation.h> @interface NSDate (SLExtend) // 判断是否是本周更早 - (BOOL)isThisWeek ...
- opencv之读取pts文件
#include <iostream> #include <fstream> #include <opencv2/opencv.hpp> using namespa ...
- POI2010题解
POI2010题解 我也不知道我为什么就开始刷POI了 有些题目咕掉了所以不完整(我都不知道POI到底有多少题) [BZOJ2079][Poi2010]Guilds (貌似bz跟洛谷上的不是一个题?) ...
- ringojs 基于jvm 的javascript 平台试用
ringojs 是一个基于jvm 的javascript 平台,支持commonjs 模块模式 安装 下载包配置环境变量,或者使用docker,测试使用docker dockerfile deb 包安 ...
- python轻量级ORM---peewee
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/q454684431/article/details/31742367 peewee是一个轻量级的OR ...
- MySQL 数据类型(float)的注意事项
摘要: 今天左哥问起一个float浮点数类型的问题,这个类型用的不多,所以也不太了解,现在打算测试下. 知识点: float:浮点数,单精度,占4字节. 测试 root@local ...
- html5 data属性的使用
html5 data属性定义和用法 <ul> <li data-animal-type="bird">Owl</li> <li data- ...
- Tomcat的最大并发数
日常应用中,单台Tomcat能支持最大的并发数是多少? 作为一个有经验的Java Web开发人员对这个问题应该有大概的印象,并会让问题再具体点,比如Tomcat版本,运行模式,并发请求允许的最大响应时 ...