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. istringstream、ostringstream、stringstream类介绍

    本文转载自: http://www.cnblogs.com/gamesky/archive/2013/01/09/2852356.html 一.C++的输入输出分为三种: (1)基于控制台的I/O ( ...

  2. layui table 数据表格 隐藏列

    现在国内的模板,也就layui一家独大了,其中的数据表格功能强大,但我不会用python或者django拼接json,输出发送给数据表格,那只好用笨办法,循环遍历吧. 数据表格中保留id列,是为了编辑 ...

  3. Ubuntu下制作系统启动盘

    制作系统U盘: $ sudo umount /dev/sdc1 $ -desktop-amd64.iso of=/dev/sdc + records in + records out bytes (1 ...

  4. I.MX6 Manufacturing Tool V2 (MFGTool2) ucl2.xml hacking

    <!-- * Copyright (C) 2010-2013, Freescale Semiconductor, Inc. All Rights Reserved. * The CFG elem ...

  5. Inno Setup 软件封装

    例子: ; 脚本用 Inno Setup 脚本向导 生成. ; 查阅文档获取创建 INNO SETUP 脚本文件的详细资料! #define MyAppName "隧道照明系统客户端程序&q ...

  6. [Luogu4899][IOI2018] werewolf 狼人

    luogu sol \(\mbox{IOI2018}\)的出题人有没有看过\(\mbox{NOI2018}\)的题目呀... \(\mbox{Kruskal}\)重构树+二维数点. 题目相当于是问你从 ...

  7. Leetcode Excel Sheet Column Number (C++) && Excel Sheet Column Title ( Python)

    Given a column title as appear in an Excel sheet, return its corresponding column number. For exampl ...

  8. coredns 代理consul 运行noamd 部署的应用

    nomad 是一个方便的应用调度平台,consul 一个很不错的服务发现工具,coredns 很不错, 扩展性比较强的dns 服务器,集成起来可能做很强大的事情 我的运行环境是mac,实际情况按需部署 ...

  9. [转载]this 指向详细解析(箭头函数)

    本文转自:http://www.cnblogs.com/dongcanliang/p/7054176.html 为了以后更方便的查看,便做了转载 前言 this 指向问题是入坑前端必须了解知识点,现在 ...

  10. Azkaban任务流编写

    在Azkaban中,一个project包含一个或多个flows,一个flow包含多个job.job是你想在azkaban中运行的一个进程,可以是Command,也可以是一个Hadoop任务.当然,如果 ...