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. 3. Map与Tuple

    一. Map 对偶 (1)对偶是一个映射.多个对偶形成map (2)对偶的表示:(k,v)或者k->v Map(哈希类型) (1)map的声明与查询 scala> val map1 = M ...

  2. ssh整合随笔(注解方式,Spring 管理action)

    Web.xml<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=" ...

  3. 系统yum源更新及某些软件官方源安装

    一.缘由 想在centos6.6上安装zabbix-agent,可是yum search 之后没有,又不想二进制安装,所以就找各种在线安装方法. 二.解决办法 思路: 1.尝试更新对应版本最新的yum ...

  4. 停止某个机房所有机器上包的脚本 pack_idc_stop.py

    一.初衷: 鉴于公司的进程包package都是冗余多点部署的,一般一个idc机房有多台机器部署同一个package.当机房网络出问题的时候,我们不得不查到本机房部署了哪些package,并在包发布系统 ...

  5. JAVA 图形界面 JFrame容器

    一.图像化界面必须引入包 //引入图形化界面包 import java.awt.*; import javax.swing.*; 二.源代码 //窗口 import java.awt.*; impor ...

  6. spring外部化配置

    例如 <bean id="dataSource" class="....." p:username="aa" p:password=& ...

  7. Linux vmstat命令--监控CPU 性能分析

    top是给Linux设计的.在FreeBSD VM里面的Free概念和其他OS完全不同,使用top查看Free内存对于FreeBSD来说可以说没什么意义.正确的方法是看vmstat. vmstat是V ...

  8. animateWithDuration 动画的速度选择

    + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnim ...

  9. 第一个APP:IOS做简单运算的计算器

    步骤: 1.打开Xcode,单机Creat a new Xcode project 2.左边选择ios下Application,右边选择single view Application 3.填写项目名称 ...

  10. NIO与传统IO的区别

    传统的socket IO中,需要为每个连接创建一个线程,当并发的连接数量非常巨大时,线程所占用的栈内存和CPU线程切换的开销将非常巨大.使用NIO,不再需要为每个线程创建单独的线程,可以用一个含有限数 ...