LeetCode刷题(21)
来源:互联网 发布:人工智能 教育风口 编辑:程序博客网 时间:2024/06/08 10:13
Wildcard Matching
?匹配单字符
* 匹配任意字符串
采用DP算法,做这类匹配问题
class Solution(object): def isMatch(self, s, p): """ :type s: str :type p: str :rtype: bool """ m = len(s) n = len(p) dp = [] for i in xrange(m+1): tmp = [] for j in xrange(n+1): tmp += False, dp += tmp, dp[0][0] = True for i in range(m+1): for j in range(1,n+1): if p[j-1] == '*': dp[i][j] = dp[i-1][j] or dp[i][j-1] elif p[j-1] == '?': dp[i][j] = i>0 and dp[i-1][j-1] else : dp[i][j] = i>0 and dp[i-1][j-1] and s[i-1] == p[j-1] return dp[m][n]
阅读全文
0 0
- Leetcode刷题(21)
- LeetCode刷题(21)
- 【leetcode】leetcode 刷题 笔记 (不定期更新)
- leetcode刷题(Python)
- LeetCode刷题(1)
- LeetCode刷题(2)
- LeetCode刷题(3)
- LeetCode刷题(废弃)
- LeetCode刷题(FizzBuzz)
- Leetcode刷题(1)
- Leetcode刷题(2)
- Leetcode刷题(3)
- Leetcode刷题(4)
- Leetcode刷题(5)
- Leetcode刷题(6)
- Leetcode刷题(7)
- Leetcode刷题(13)
- Leetcode刷题(17)
- jquery实现弹框,背景变黑
- PHP正则表达式
- 测试httpclient时,报 406错误的解决方法(临时解决)
- 函数参数传递
- 找到与众不同的那个小球(C语言)
- LeetCode刷题(21)
- linux 基础学习4
- Ubuntu安装tplink wn822n网卡驱动
- c语言(三)字符串、数组
- C#基础(5)——三元表达式
- Redis的服务端安装
- 筛选法
- java鬼混笔记:springboot 8、springboot发邮件mail
- 妖梦拼木棒(组合数学)