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)的更多相关文章

  1. [Leetcode][Python]28: Implement strStr()

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 28: Implement strStr()https://oj.leetco ...

  2. 28. Implement strStr()【easy】

    28. Implement strStr()[easy] Implement strStr(). Returns the index of the first occurrence of needle ...

  3. leetCode练题——28. Implement strStr()

    1.题目 28. Implement strStr()——Easy Implement strStr(). Return the index of the first occurrence of ne ...

  4. 44. leetcode 28. Implement strStr()

    28. Implement strStr() Implement strStr(). Returns the index of the first occurrence of needle in ha ...

  5. C# 写 LeetCode easy #28 Implement strStr()

    28.Implement strStr() Implement strStr(). Return the index of the first occurrence of needle in hays ...

  6. [LeetCode] 28. Implement strStr() 实现strStr()函数

    Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...

  7. 【LeetCode】28 - Implement strStr()

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  8. Java [leetcode 28]Implement strStr()

    题目描述: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if ...

  9. [LeetCode] 28. Implement strStr() 解题思路

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

随机推荐

  1. zabbix利用python脚本发送钉钉报警

    #!/usr/bin/python # -*- coding: utf-8 -*- import requests import json import sys import os headers = ...

  2. Visual C#中的winform/webform/asp.net控件命名规范

                                                                            1.控件命名规范 类型 前缀 示例 AdRotator ...

  3. 【转载】python安装numpy和pandas

    转载:原文地址 http://www.cnblogs.com/lxmhhy/p/6029465.html 最近要对一系列数据做同比比较,需要用到numpy和pandas来计算,不过使用python安装 ...

  4. k8s PersistentVolume hostpath 简单使用

    kubernets host PersistentVolume 测试 因为yaml 格式的问题 ,我修改为了json 创建 pv pv.json { "kind": "P ...

  5. deno学习一 安装试用&&几个问题解决

      基本的依赖可以参考github 我的环境是centos 7 基本安装 需要golang 以及yarn安装 Protobuf 3 这是官方的方式,实际可以变通下 cd ~ wget https:// ...

  6. DataTable快速定制之Expression属性表达式

    本文旨在讨论使用DataColumn.Expression属性定制列,高手绕过. 这里只介绍两个经典的场景,抛砖引玉其他更多功能待各位读者自己发现吧! 场景一: DataTable里有两个列分别为每种 ...

  7. Web验证方式(4)--JWT

    OAuth协议中说到的AccessToken可以是以下两种: 1.任意只起到标识作用的字符串:这种情况下Resource Server处理请求时需要去找Authorization Server获取用户 ...

  8. decimal类型运算注意点

    代码如下: //货币类型的两个数基本运算 Console.WriteLine("错误的写法"); - ); ; - ) / ; Console.WriteLine(errorNum ...

  9. 给VS类文件添加默认头注释

    找到类文件所在路径:C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ItemTemplatesCache\CSharp\ ...

  10. POJ 1258 Agri-Net (prim水题)

    Agri-Net Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) Total Subm ...