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 ...
随机推荐
- Ubuntu16.04彻底卸载MySQL
删除mysql的数据文件 sudo rm /var/lib/mysql/ -R 删除mysql的配置文件 sudo rm /etc/mysql/ -R 自动卸载mysql(包括server和clien ...
- 富文本之BootStrap-wysiwyg 带图片上传功能
BootStrap-wysiwyg插件具有良好的编辑功能和展示效果. 一.使用方法在网上有很多,在此记录自己使用过程中的一些问题和解决方式. 相关依赖: bootstrap-wysiwyg.js (核 ...
- This Debug perspective is designed to support application debugging.it incorporates views for displaying the debug stack,variables and breakpoint mamagement
使用IDE(Eclipse Version:Neon.2 Release (4.6.2)),出现以下提示信息: This kind of launch is configured to openthe ...
- CentOS 7 MariaDB-MHA
关于MHA MHA(Master High Availability)是一款开源的mysql高可用程序,目前在mysql高可用方面是一个相对成熟的解决方案.MHA 搭建的前提是MySQL集群中已 ...
- nc linux命令详解
NetCat,在网络工具中有“瑞士军刀”美誉,其有Windows和Linux的版本.因为它短小精悍(1.84版本也不过25k,旧版本或缩减版甚至更小).功能实用,被设计为一个简单.可靠的网络工具,可通 ...
- 浅谈react的初步试用
现在最热门的前端框架,毫无疑问是 React . 上周,基于 React 的 React Native 发布,结果一天之内,就获得了 5000 颗星,受瞩目程度可见一斑. React 起源于 Face ...
- 使用freemarker和itext把html转pdf
1.把html转pdf,首先必须要解决中文显示问题,CSS样式问题以及可能的JS问题,先上例子,自己去体会. 2.先去下载simsun.ttc字体: 2.demo.html <!DOCTYPE ...
- ACM总结——2017ACM-ICPC北京赛区现场赛总结
现在距离比赛结束已经过了一个多星期了,也是终于有时间写下心得了.回来就是被压着做项目,也是够够的. 这次比赛一样是我和两个学弟(虽然是学弟,但我的实力才是最弱的T_T)一起参加的,成绩的话打铁,算是情 ...
- 51Nod 博弈模板题
连刷3道博弈模板题,算是稍微学习了以下三个经典博弈了.推荐一个博客. 第一道模板:Bash博弈——同余理论 1066 Bash游戏 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度 ...
- Linux学习笔记之时间同步the NTP socket is in use, exiting问题
[root@app1 ~]# ntpdate ntp.api.bz 17 Apr 14:39:09 ntpdate[24744]: the NTP socket is in use, exiting ...