当前位置:网站首页>剑指Offer(五十二):正则化表达式
剑指Offer(五十二):正则化表达式
2022-07-26 10:36:00 【康斯坦奇】
考虑的情况太多了,目前还没搞懂,先把代码贴上!
class Solution:
# s, pattern都是字符串
def match(self, s, pattern):
# write code here
if len(s) == 0 and len(pattern) == 0:
return True
elif len(s) != 0 and len(pattern) == 0:
return False
elif len(s) == 0 and len(pattern) != 0:
if len(pattern) > 1 and pattern != 0:
return self.match(s,pattern[2:])
else:
return False
else:
if len(pattern) > 1 and pattern[1] == '*':
if s[0] != pattern[0] and pattern[0] != '.':
return self.match(s,pattern[2:])
else:
return self.match(s,pattern[2:]) or self.match(s[1:],pattern[2:]) or self.match(s[1:],pattern)
else:
if s[0] == pattern[0] or pattern[0] == '.':
return self.match(s[1:],pattern[1:])
else:
return False
边栏推荐
- .net operation redis hash object
- [C language] named type and anonymous type
- Redis Docker实例与数据结构
- Redis docker instance and data structure
- Issue 8: cloud native -- how should college students learn in the workplace
- [leetcode每日一题2021/2/13]448. 找到所有数组中消失的数字
- C语言计算日期间隔天数
- Analyze the hybrid construction objects in JS in detail (construction plus attributes, prototype plus methods)
- 比较器(Comparable与Comparator接口)
- .net5wtm (asp.net core) PgSQL unpacking operation
猜你喜欢
[Halcon vision] morphological expansion
Application of.Net open source framework in industrial production
STM32 Alibaba cloud mqtt esp8266 at command
Tradingview 使用教程
canvas上传图片base64-有裁剪功能-Jcrop.js
videojs转canvas暂停、播放、切换视频
[Halcon vision] programming logic
码云,正式支持 Pages 功能,可以部署静态页面
Dry goods likeshop takeout order system is open source, 100% open source, no encryption
异常的概念与处理
随机推荐
[Halcon vision] affine transformation
Centos8 (liunx) deploying WTM (asp.net 5) using PgSQL
父类对子类的引用(父类引用指向子类对象)
第5期:大学生入职必备技能之二
Oracle创建索引
移动端双指缩放事件(原生),e.originalEvent.touches
Unit test, what is unit test and why is it so difficult to write a single test
Structure of [Halcon vision] operator
第4期:大学生提前职业技能准备之一
使用Geoprocessor 工具
分布式锁解决方案之Redis实现
Tradingview 使用教程
L2-005 集合相似度(vector、set求并交集)
Interview questions and answers of the first company (I)
Controller返回JSON数据
Uninstall Meizu app store
从蚂蚁的觅食过程看团队研发(转载)
What if MySQL can't get in
第7期:内卷和躺平,你怎么选
oracle 启动不了 tnslistener服务启动不了