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. Navicat 11使用技巧

    入门 Navicat 是一个可多重连接的数据库管理工具,它可让你连接到 MySQL.Oracle.PostgreSQL.SQLite.SQL Server 和/或 MariaDB 数据库,让管理不同类 ...

  2. Chrome安装FlashPlayer Debug

    首先: 在谷歌浏览器上打开chrome://plugins 找到 Adobe Flash Player 然后将谷歌自带的版本停用,如果已经安装了for Netscape版,则会显示另外一个版本.(建议 ...

  3. SqlServer调用外部程序实现数据同步

    首先创建两个数据库:SyncA是数据源,SyncB是对SyncA进行同步的数据库. 在SyncA和SyncB中分别创建Source表和Target表,实际业务中,两张表的结构大多不相同.     然后 ...

  4. 冲突--ScrollView嵌套ListView只显示一行

    在开发的过程当中,由于手机屏幕的大小的限制,我们经常需要使用滑动的方式,来显示更多的内容.在最近的工作中,遇见一个需求,需要将ListView嵌套到ScrollView中显示.于是乎有了如下布局: & ...

  5. 【转】C++ 单例模式

    http://blog.csdn.net/hackbuteer1/article/details/7460019 单例的一般实现比较简单,下面是代码和UML图.由于构造函数是私有的,因此无法通过构造函 ...

  6. 问对于一个给定的n,怎样才能用最少的步骤将它变到1

    如果n为偶数,则将它除以2,如果n为奇数,则将它加1或者减1.问对于一个给定的n,怎样才能用最少的步骤将它变到1.例如:n= 61n-- 60n/2 30n/2 15n++ 16n/2 8n/2 4n ...

  7. 手机端的各种默认样式比如 ios的按钮变灰色

    1.ios按钮变灰色,给按钮加样式: -webkit-appearance: none; 2.有圆角话 ; } 3.去除Chrome等浏览器文本框默认发光边框 input:focus, textare ...

  8. java常用面板

    public class JPanelTest extends JFrame{    public JPanelTest(){        Container c=getContentPane(); ...

  9. 【转】android的一些开源项目

    自己一直很喜欢Android开发,就如博客副标题一样,我想做个好的App. 在摸索过程中,GitHub上搜集了很多很棒的Android第三方库,推荐给在苦苦寻找的开发者,而且我会不定期的更新这篇文章. ...

  10. Arrays

    Arrays:用于操作数组对象的工具类,里面都是静态方法. asList方法:将数组转换成list集合. String[] arr = {"abc","kk", ...