#-*- coding: UTF-8 -*-
#题意:大海捞刀,在长字符串中找出短字符串
#AC源码:滑动窗口双指针的方法
class Solution(object):
    def strStr(self, hayStack, needle):
        """
        :type haystack: str
        :type needle: str
        :rtype: int
        """
        if len(needle)>len(hayStack):return -1
        lenN=len(needle)
        needleDic=[];hayStackDic=[]
        for i  in xrange(len(needle)):
            needleDic.append(needle[i])
        for i in xrange(0,len(needle)):
              hayStackDic.append(hayStack[i])
        i=0      
        while 1:
            if needleDic==hayStackDic:
                return i
            del hayStackDic[0]
            if i+lenN>len(hayStack):break
            hayStackDic.append(hayStack[i+lenN])
            i+=1
        return -1

sol=Solution()
print sol.strStr("pi","pi")

【leetcode❤python】 28. Implement strStr()的更多相关文章

  1. 【leetcode❤python】 225. Implement Stack using Queues

    #-*- coding: UTF-8 -*-class Stack(object):    def __init__(self):        """        i ...

  2. 【leetcode❤python】232. Implement Queue using Stacks

    #-*- coding: UTF-8 -*-#双栈法class Queue(object):    def __init__(self):        """      ...

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

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

  4. 【LeetCode】28. Implement strStr() 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 find函数 遍历+切片 日期 题目地址:https ...

  5. 【一天一道LeetCode】#28. Implement strStr()

    一天一道LeetCode系列 (一)题目 Implement strStr(). Returns the index of the first occurrence of needle in hays ...

  6. 【LeetCode】28 - Implement strStr()

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

  7. 【LeetCode】28. Implement strStr() (2 solutions)

    Implement strStr() Implement strStr(). Returns a pointer to the first occurrence of needle in haysta ...

  8. 【leetcode❤python】Sum Of Two Number

    #-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...

  9. LeetCode记录之28——Implement strStr()

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

随机推荐

  1. VC++6.0编译器标记的那些内存值

    栈内存初始值 0xcccccccc 和-858993460.   二者是一样的, 一个是16进制, 另一个是10进制

  2. Ubuntu Linux上安装配置Mysql

    一.安装: 三种安装方式: 1. 从网上安装 sudo apt-get install mysql-server.装完已经自动配置好环境变量,可以直接使用mysql的命令. 注:建议将/etc/apt ...

  3. git总是出现untracked content怎么解决?

    git rm --cached vendor/plugins/open_flash_chart_2 rm -rf vendor/plugins/open_flash_chart_2/.git # BA ...

  4. 奥迪--A6L

    -型号:A6L -价格:42-75W -动力:1.8T/2.5L/3T -变速箱:7挡双离合/CVT无级变速/7挡双离合 -长宽高:5.04,1.87,1.47 -油箱:75L -发动机:EA888 ...

  5. LightOj 1220 - Mysterious Bacteria (分解质因子x=b^p 中的 x 求最大的 p)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1220 题意:已知 x=bp 中的 x 求最大的 p,其中 x b p 都为整数 x = ...

  6. Python开发【第九章】:线程、进程和协程

    一.线程 线程是操作系统能够进行运算调度的最小单位.它被包含在进程之中,是进程中的实际运作单位.一条线程指的是进程中一个单一顺序的控制流,一个进程中可以并发多个线程,每条线程并行执行不同的任务 1.t ...

  7. 怎样实现excel隔行隔列变色效果的方法

    大家在使用excel的过程中,一定见过别人编排的excel文档,隔行添加单元格背景颜色,也就是通常所说的隔行变色效果.Excel中隔行变色效果的好处是:当在Excel中浏览一个非常大的工作簿中的数据时 ...

  8. Oracle 小案例

    create database cstd; use cstd; /*1:建立学生表*/ create table student ( 学号 ) primary key, 姓名 ), 性别 ), 年龄 ...

  9. cocos2dx 3.x(屏幕截图的两种方法)

    [RenderTexture] RenderTexture这个动态纹理类,顾名思义就是可以动态创建纹理图片. 屏幕截图主要步骤: > 开始截图:render->begin(); >  ...

  10. 循环调用MAIN

    --单位转移录入declare oi_errcode integer; oc_errtext varchar2(100);begin for p in (select * from ssunitinf ...