#实现正则表达式匹配并支持'.'和'*'。
#''匹配任何单个字符。
#'*'匹配前面元素的零个或多个。
#匹配应覆盖整个输入字符串(非部分)。
##Some examples:
##isMatch("aa","a") → false
##isMatch("aa","aa") → true
##isMatch("aaa","aa") → false
##isMatch("aa", "a*") → true
##isMatch("aa", ".*") → true
##isMatch("ab", ".*") → true
##isMatch("aab", "c*a*b") → true

def ismatch(s,re):
    l=[]
    for k in range(len(re)):
        if re[k]=='*':
            l.append(k)
    re=''.join(re.split('*'))
    for i in range(len(l)):
        l[i]=l[i]-i-1
    print(re)
    print(l)
    flg=0
    for i in range(len(s)):
        ## *退出
        while flg  in l and s[i]!=re[flg] and re[flg]!='.':            
            flg+=1
        if flg==len(re):
            return False,'re too short'
        if flg  not in l:
            if s[i]==re[flg] or re[flg]=='.':
                flg+=1
            else:
                return False,'no *'
        if i==len(s)-1:
            if flg==len(re):
                return True,'perfect'
            else:
                return False,'re too long'

print(ismatch("aaaaab", "c*a*."))

leetcode python 010的更多相关文章

  1. Leetcode Python Solution(continue update)

    leetcode python solution 1. two sum (easy) Given an array of integers, return indices of the two num ...

  2. LeetCode python实现题解(持续更新)

    目录 LeetCode Python实现算法简介 0001 两数之和 0002 两数相加 0003 无重复字符的最长子串 0004 寻找两个有序数组的中位数 0005 最长回文子串 0006 Z字型变 ...

  3. [LeetCode][Python]Container With Most Water

    # -*- coding: utf8 -*-'''https://oj.leetcode.com/problems/container-with-most-water/ Given n non-neg ...

  4. LeetCode Python 位操作 1

    Python 位操作: 按位与 &, 按位或 | 体会不到 按位异或 ^ num ^ num = 0 左移 << num << 1 == num * 2**1 右移 & ...

  5. 【leetcode❤python】Sum Of Two Number

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

  6. [Leetcode][Python]56: Merge Intervals

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 56: Merge Intervalshttps://oj.leetcode. ...

  7. [Leetcode][Python]55: Jump Game

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 55: Jump Gamehttps://leetcode.com/probl ...

  8. [Leetcode][Python]54: Spiral Matrix

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 54: Spiral Matrixhttps://leetcode.com/p ...

  9. [Leetcode][Python]53: Maximum Subarray

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 53: Maximum Subarrayhttps://leetcode.co ...

随机推荐

  1. laravel自定义验证

    1.在控制器中直接写验证$this->validate($request, [ 'video_ids' => [ function($attribute, $value, $fail) { ...

  2. n皇后问题——关于斜线的编号

    题目大意:在n*n的棋盘中,放置n个皇后(同一行.同一列.同一斜线,只有一个皇后) 这道题是一道非常经典的dfs模板题,同一行.同一列的判断不是很难,但同一斜线有一定的难度,下面给出关于斜线编号的解决 ...

  3. vue用npm安装删除模块element-ui mint-ui

    vue用npm安装删除模块element-ui mint-ui 在vue项目中先引入了element-ui,后来发现移动版的需要用mint-ui,所以需要先卸载了再安装.卸载element-ui:np ...

  4. PriorityQueue 源码分析

    public boolean hasNext() { return cursor < size || (forgetMeNot != null && !forgetMeNot.i ...

  5. Python+OpenCV图像处理(十六)—— 轮廓发现

    简介:轮廓发现是基于图像边缘提取的基础寻找对象轮廓的方法,所以边缘提取的阈值选定会影响最终轮廓发现结果. 代码如下: import cv2 as cv import numpy as np def c ...

  6. linux中make的有关规则的特性

    我过去认为 makefile 只是一种将一组组的 shell 命令列出来的简便方法:过了一段时间我了解到它们是有多么的强大.灵活以及功能齐全.这篇文章带你领略其中一些有关规则的特性. 规则 规则是指示 ...

  7. 复习-css控制文本字体属性

    css控制文本字体属性 font-family:字体系列,如”serif“”sans-serif“ font-size:尺寸 font-style:字体样式,如“normal,italic(斜体).o ...

  8. linux --- 7. 路飞学城部署

    一.前端 vue 部署 1.下载项目的vue 代码(路飞学城为例), wget https://files.cnblogs.com/files/pyyu/07-luffy_project_01.zip ...

  9. 原生JS实现简易转盘抽奖

    我爱撸码,撸码使我感到快乐. 大家好,我是Counter. 本章带大家来简单的了解下原生JS实现转盘抽奖. 因为主要涉及到JS,在这里HTML和CSS起到的功能就没有那么重要, 因此,没有过多的阐述H ...

  10. JAVA中的责任链模式(CH02)

    对责任链CH01做出优化,解决耦合度太高问题 记得上一篇我们使用的是抽象类,然后用子类去继承的方法实现等级的桥接,从而发现了耦合度太高. 为了解决这个问题. 我们本次使用接口进行抽象,然后使用到一个” ...