leetcode 44. Wildcard Matching
来源:互联网 发布:数组 push 编辑:程序博客网 时间:2024/06/05 20:21
难度:hard
题目:
与leetcode10. Regular Expression Matching此题类似,同样采用动态规划,这两题解法很精彩,比较经典
AC解:
class Solution {public: bool isMatch(string s, string p) { int slen = s.length(); int plen = p.length(); if (slen == 0 && plen == 0) return true; vector<vector<bool>> dp(slen + 1, vector<bool>(plen + 1, false)); //初始化数组 dp[0][0] = true; for (int i = 0; i < plen && p[i] == '*'; i++) dp[0][i + 1] = true; for (int i = 1; i < slen + 1; i++) for (int j = 1; j < plen + 1; j++) { if (s[i - 1] == p[j - 1] || p[j - 1] == '?') dp[i][j] = dp[i - 1][j - 1]; if (p[j - 1] == '*') { dp[i][j] = dp[i - 1][j] || dp[i][j - 1]; } } return dp[slen][plen]; }};
阅读全文
0 0
- LeetCode --- 44. Wildcard Matching
- [Leetcode] 44. Wildcard Matching
- Leetcode 44. Wildcard Matching
- leetcode 44. Wildcard Matching
- Leetcode 44. Wildcard Matching
- Leetcode:44. Wildcard Matching
- LeetCode 44. Wildcard Matching
- leetcode.44. Wildcard Matching
- LeetCode 44. Wildcard Matching
- Leetcode-44. Wildcard Matching
- [LeetCode] 44. Wildcard Matching
- [leetcode] 44. Wildcard Matching
- [LeetCode]--44. Wildcard Matching
- LeetCode 44. Wildcard Matching
- leetcode 44. Wildcard Matching
- LeetCode 44. Wildcard Matching
- 44. Wildcard Matching -- LeetCode
- LeetCode 44. Wildcard Matching
- rem的“分辨率”
- IDEA删除项目 更新maven
- Git 分支管理
- 容器编排Kubernetes之kube-dns源码解读
- css的网页布局
- leetcode 44. Wildcard Matching
- 三星S5P4418核心板,ARM Cortex-A9架构
- 30:字符环( 1.7编程基础之字符串)
- 网易堆棋子(%60通过率,超内存)
- 常用meta整理
- 站点管理平台化
- Spring-cloud微服务学习入门教程
- PPT组件Aspose.Slides V17.8发布 | 支持PP2010 PPTX与嵌入式视频
- js函数重载方法1---待 未看懂