【LeetCode笔记】Wildcard Matching 和 Regular Expression Matching

这两道题第一眼看上去都差不多,通常思路就是用动态规划做。

对于Regular Expression Matching可以50ms通过所有test case; 

而对于Wildcard Matching却需要900ms.

不知道OJ用了什么不同的test case,但是DP的时间复杂度是M*N的,没道理差别这么大。Dissuss里很多人用DP还不能通过。

原因可能如下:

bool OPT[m+1][n+1]

size of the mentioned test case : s.size()= 32316, p.size(): 32318

This means a memory location of 32317*32319 bytes is required which is way past the maximum limit allowed for continuous memory allocation with an array structure.

 answered Oct 9 by leet_nik (1,050 points)

看了Accepted Solution Runtime Distribution后,才发现Wildcard Matching有“线性”做法,就是Yu的做法:

http://yucoding.blogspot.com/2013/02/leetcode-question-123-wildcard-matching.html

但是Yu的算法worst case running time 也是M*N的。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值