第五天
来源:互联网 发布:会员卡系统java源代码 编辑:程序博客网 时间:2024/04/28 13:37
第五天
今天leetcode 晚上的时候挂掉了。。
今天主要的时间都用来写报告了
图形学报告,,,c#报告。。。。
本来想非递归实现的,最后死于如果s都被匹配上p是否呗用完的纠结上。。
最后还是递归实现吧。
def isMatch(s, p): len1 = len(s) len2 = len(p) dp = [] dp2 = [] dp.append(1) dp2.append(1) for i in range(len1): dp.append(0) dp2.append(0) for x in range(1,len2+1): if p[x-1] == '*': continue if x<len2: if p[x]=='*': for y in range(1,len1+1): if s[y-1] == p[x-1]or p[x-1] == '.': dp[y] = max(dp2[y-1],dp[y-1]) temp = dp2 dp2 = dp dp = temp continue for y in range(1,len1+1): if s[y-1] == p[x-1] or p[x-1] == '.': dp[y] = dp2[y-1] print dp temp = dp2 dp2 = dp dp = temp if dp[len1] == 1: return True else: return Falseprint isMatch('aaa','aaaa')
递归实现代码
class Solution: # @param {string} s # @param {string} p # @return {boolean} def isMatch(self, s, p): if not s and not p: return True if not p and s: return False if p[-1] == '*': rep = p[-2] if s and (s[-1] == rep or rep == '.'): return self.isMatch(s[:-1], p) or self.isMatch(s, p[:-2]) else: return self.isMatch(s, p[:-2]) else: if s and (p[-1] == s[-1] or p[-1] == '.'): return self.isMatch(s[:-1], p[:-1]) else: return False
明天继续研究这个题, 一定要非递归实现成功一次,贵在坚持
0 0
- 第五天
- 第五天
- 第五天
- 第五天
- 第五天
- 第五天
- 第五天
- 第五天
- 第五天
- 第五天
- 第五天
- 第五天
- 第五天
- 第五天
- 第五天
- 第五天
- 第五天
- 第五天
- OC数据持久化方案2-NSKeyedArchiver归档
- 【Android】利用相对布局布置更新软件的style为主题对话框的Activity,利用layout_weight属性对表格布局的行划分
- WebService—快速实现一个基于JAX-WS的WebService项目(一)
- oracle-过程函数编程
- RBAC权限管理1
- 第五天
- 试题2
- Hello JavaScript!
- [pySpark][笔记]spark tutorial from spark official site在ipython notebook 下学习pySpark
- 作为一个初来乍到准备做IT的外来人,写写东西纪念一下
- LeetCode——Reverse Linked List
- spring MVC拦截器01
- 小圆贴大圆内侧滚动,求小圆上指定一点的运动轨迹
- spring+hibernate:在applicationCOntext.XML中配置C3P0参数说明Attempted to use a closed or broken resource pool