class Solution {
public:
int strStr(string haystack, string needle) {
if(needle.empty())return ; //needle empty
if(haystack.empty()) return -; //haystack empty
for(int i = , j = ; i+j < haystack.size();) {
if(haystack[i+j] != needle[j])i++, j = ; //no equal needle index to 0, haystack index move to next.
else j++; //equal both move to next
if(j == needle.size())return i; //thr first time find substr.
}
return -;
}
};

Leetcode028. Implement strStr()的更多相关文章

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

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

  2. 28. Implement strStr()

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

  3. Leetcode 详解(Implement strstr)

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

  4. [leetcode 27]Implement strStr()

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

  5. Leetcode #28. Implement strStr()

    Brute Force算法,时间复杂度 O(mn) def strStr(haystack, needle): m = len(haystack) n = len(needle) if n == 0: ...

  6. 【leetcode】Implement strStr() (easy)

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

  7. [LeetCode] Implement strStr()

    Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if need ...

  8. Implement strStr()

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

  9. Implement strStr() [LeetCode]

    Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if need ...

随机推荐

  1. 我的wordpress插件总结

    酷壳(CoolShell.cn)WordPress的插件 注意: 下面的这些插件的链接是其插件主页的链接,你可以在WordPress后台管理中添加插件时直接搜索安装就可以了. 插件不是越多越好.WP的 ...

  2. .net EntityFramework用法探索系列 1

    EntityFramework用法探索系列 (一)DatabaseFirst (二)CodeFirst (三)CodeFirst流畅API (四)Repository和UnitOfWork (五)引入 ...

  3. unity c#

    gameObject //获取当前脚本挂载到的游戏对象 在Unity中就算使用了C#进行编写脚本,要输出时不能使用Console类,应当使用print();或者Debug.log(); transfo ...

  4. JAVA 构造代码块

    class G{ G(){ System.out.println("我是无参构造方法"); } G(String name){ System.out.println("我 ...

  5. mac下Android开发环境搭建

    之前一段时间在学习ios的开发,近一段时间想着也接触下Android开发,以来加深对移动端开发的理解.这里根据自己配置Android开发环境的过程,比较详细的来总结下自己的安装过程,希望对一些正准备配 ...

  6. js实现加减乘除

    /** ** 除法函数,用来得到精确的除法结果 ** 说明:javascript的除法结果会有误差,在两个浮点数相除的时候会比较明显.这个函数返回较为精确的除法结果. ** 调用:accDiv(arg ...

  7. C语言位运算符及作用:与、或、异或、取反、左移和右移

    一.& 按位与 如果两个相应的二进制位都为1,则该位的结果值为1,否则为0应用:(1)清零 若想对一个存储单元清零,即使其全部二进制位为0,只要找一个二进制数,其中各个位符合一下条件:原来的数 ...

  8. Liferay中SQL打印参数

      XX\tomcat-7.0.42\webapps\ROOT\WEB-INF\classes\log4j.properties log4j.rootLogger=INFO, CONSOLE log4 ...

  9. Java中的JDBC基础

    简介 JAVA程序想要对数据库进行访问,需要有JDBC驱动程序的支持.JDBC驱动程序提供了对各种主流数据库的接口,程序员只需要学习掌握这一套接口,就可以实现对所有数据库的访问代码编写. 一般步骤 J ...

  10. C Primer Plus(第五版)2

    在本章中你将学习下列内容------------------------------------------------------------------1.运算符:= 2.函数:main(),pr ...