leetcode python 010
#实现正则表达式匹配并支持'.'和'*'。
#''匹配任何单个字符。
#'*'匹配前面元素的零个或多个。
#匹配应覆盖整个输入字符串(非部分)。
##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的更多相关文章
- Leetcode Python Solution(continue update)
leetcode python solution 1. two sum (easy) Given an array of integers, return indices of the two num ...
- LeetCode python实现题解(持续更新)
目录 LeetCode Python实现算法简介 0001 两数之和 0002 两数相加 0003 无重复字符的最长子串 0004 寻找两个有序数组的中位数 0005 最长回文子串 0006 Z字型变 ...
- [LeetCode][Python]Container With Most Water
# -*- coding: utf8 -*-'''https://oj.leetcode.com/problems/container-with-most-water/ Given n non-neg ...
- LeetCode Python 位操作 1
Python 位操作: 按位与 &, 按位或 | 体会不到 按位异或 ^ num ^ num = 0 左移 << num << 1 == num * 2**1 右移 & ...
- 【leetcode❤python】Sum Of Two Number
#-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...
- [Leetcode][Python]56: Merge Intervals
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 56: Merge Intervalshttps://oj.leetcode. ...
- [Leetcode][Python]55: Jump Game
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 55: Jump Gamehttps://leetcode.com/probl ...
- [Leetcode][Python]54: Spiral Matrix
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 54: Spiral Matrixhttps://leetcode.com/p ...
- [Leetcode][Python]53: Maximum Subarray
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 53: Maximum Subarrayhttps://leetcode.co ...
随机推荐
- ListView的BeginUpdate()和EndUpdate()的用处
许多Windows 窗体控件(例如,ListView 和 TreeView 控件)实现了 BeginUpdate 和EndUpdate 方法,至于为何要这样用简单说明一下. 当我们向一个Listvie ...
- 移动端热更新方案(iOS+Android)
PPT资源包含iOS+Android 各种方案分析:https://github.com/qiyer/Share/blob/master/%E7%83%AD%E6%9B%B4%E6%96%B0%E5% ...
- 调度器的实现、schedule、switch_context、switch_to
根据<深入Linux内核架构>和Linux-3.10.1内核源码,记一些调度过程的主体工作. 调度器任务:CPU数目比要运行的进程数目少,需要程序之间共享CPU时间,创造并行执行的错觉.分 ...
- Windows 服务器自动重启定位
有个非常好的小技巧,就是在服务器端命令行,执行systeminfo,能查到服务器上一次重启的时间,依照这个时间在Event Log里再找相应的日志就容易多了. 补充:还能查到这台服务器是虚拟机还是实体 ...
- 第六节 DOM操作应用
创建.插入和删除元素 创建DOM元素: createElement(标签名); //创建一个节点 appendChild(节点); //追加一个节点 例如:document.body.appendCh ...
- php在cli模式下取得命令行中的参数的方法-getopt命令行可传递数组-简单自定义方法取命令行参数
在cli模式下执行PHP时,自动给脚本文件传递了一个变量$argv,其值即是一个命令中所有值组成的数组(以空格区分),在PHP程序中接收参数有3种方法1.直接使用argv变量数组. 2.使用$_SER ...
- python爬虫——对爬到的数据进行清洗的一些姿势(5)
做爬虫,当然就要用数据.想拿数据进行分析,首先清洗数据.这个清洗数据包括清除无用数据列和维度,删除相同数据,对数据进行勘误之类的. 从各大不同新闻网站可以爬到重复新闻...这个可以有.之前为了对爬到的 ...
- freeswitch 显示主叫名称和主叫号码
1.指定主叫号码 origination_caller_id_number 参数来指定显示的主叫号码 2.指定主叫名称 origination_caller_id_name 参数来指定显示的主叫名称 ...
- Learning-Python【10】:函数初识
一.什么是函数 函数就是代码的一种组织形式,是指将一组语句的集合通过一个名字(函数名)封装起来,要想指向这个函数,只需要调用其函数名即可 函数分为两大类:内置函数 和 自定义函数 二.为何要用函数 减 ...
- easyUI使用dailog实现弹出框带表单功能
本文为博主原创,未经允许不得转载: 示例如下: 需要注意的地方在id为win的div中需要有:closed="true"这个属性,这个属性为控制dailogn对话框显示与隐藏的属性 ...