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 ...
随机推荐
- 《次元唤醒 需求规格说明书v1.0》
一.团队分工 组员 工作比例 参与范围 王诚荣 17% 原型设计,需求规格说明书整合,LOGO设计 马祎特 22% PPT制作,演讲,博客模板,用户描述 陈斌 21% 评审表格制作,引言,项目描述,功 ...
- XMU 1246
http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1246 求区间内素数个数,经典问题,区间长度10^6,数的取值最多能到10^12(此题范围稍小) 用 ...
- 浅谈闭包(Closure)
一.闭包 好长时间对于闭包都知道与函数和其环境变量有关系,但是一直没有一个清晰的认识.今天查看了一下维基百科,顺便写下来. 二.闭包的定义 在编程语言中,闭包(语义闭包或函数闭包)是指哪些可以将语义范 ...
- 华为OJ:2199 推断输入字符串中的括号匹配
依据不同的括号有个计数器.在遍历时.当计数器小于0则返回false或者当遍历完后,计数器仍旧不为零,也返回false. import java.util.Scanner; public class b ...
- 由spring的工厂构造bean想到的
被Spring管理的bean可以是直接创建实例,还可以通过工厂模式来进行创建.例如brave的tracing bean定义: <bean id="tracing" class ...
- SQL相关简单游标
BEGIN TRY Create Table #Temp_Table_Record_Stat ( .... ) DECLARE table_Cursor CURSOR FOR SELECT objec ...
- [C++ Primer] 第7章: 类
定义抽象数据类型 定义在类内部的函数是隐式的inline函数. const成员函数 又叫做常量成员函数, 成员函数参数列表之后紧跟const关键字, const修饰的是类this指针. 默认情况下th ...
- 堆排序算法-python实现
#-*- coding: UTF-8 -*- import numpy as np def MakeHeap(a): for i in xrange(a.size / 2 - 1, -1, -1):# ...
- 【pc杂谈】win7系统通过虚拟网卡共享wifi
用管理员权限进入dos命令行 启用并设定虚拟WiFi网卡:netsh wlan set hostednetwork mode=allow ssid=paulnet key=paulwinflo(注意 ...
- java web 程序---内置对象application的log方法的使用
application的主要方法里,有log方法,是日志文件里可以查看到信息的. 当老师写好代码后,他发现在tomact里的log目录下找不到信息,原因是:我们用myeclipse这个客户端软件,应该 ...