[leetcode]44. Wildcard Matching(Java)
来源:互联网 发布:燕郊招聘淘宝客服 编辑:程序博客网 时间:2024/05/22 06:57
https://leetcode.com/problems/wildcard-matching/#/description
Implement wildcard pattern matching with support for ‘?’ and ‘*’.
‘?’ Matches any single character.
‘*’ Matches any sequence of characters (including the empty sequence).
The matching should cover the entire input string (not partial).
The function prototype should be:
bool isMatch(const char *s, const char *p)
Some examples:
isMatch(“aa”,”a”) ? false
isMatch(“aa”,”aa”) ? true
isMatch(“aaa”,”aa”) ? false
isMatch(“aa”, “*”) ? true
isMatch(“aa”, “a*”) ? true
isMatch(“ab”, “?*”) ? true
isMatch(“aab”, “c*a*b”) ? false*强调内容*
package go.jacob.day708;
/**
* 44. Wildcard Matching
*
* @author Jacob
*
*/
public class Demo2 {
/*
* 方法一:参考自10. Regular Expression Matching的解法
*/
public boolean isMatch(String s, String p) {
if (s == null || p == null)
return false;
boolean[][] res = new boolean[s.length() + 1][p.length() + 1]; res[0][0] = true; for (int i = 0; i < p.length(); i++) { if(p.charAt(i)=='*') res[0][i+1]=res[0][i]; } for(int i=0;i<s.length();i++){ for(int j=0;j<p.length();j++){ if(p.charAt(j)=='?'||p.charAt(j)==s.charAt(i)) res[i+1][j+1]=res[i][j]; if(p.charAt(j)=='*'){ res[i+1][j+1]=res[i+1][j]||res[i][j+1]; } } } return res[s.length()][p.length()];}
}
- (Java)LeetCode-44.Wildcard Matching
- [leetcode]44. Wildcard Matching(Java)
- [leetcode]44. Wildcard Matching(Java)
- [Leetcode] Wildcard Matching (Java)
- 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
- Android-------自定义View圆形进度条
- ubuntu下opencv 3.2配置
- 技术闲置是浪费,你应该分享!
- C语言中的预处理详解
- Buffer详解
- [leetcode]44. Wildcard Matching(Java)
- poj 1088 滑雪
- 【Unity学习笔记】——基础篇:多细节层次LOD技术
- 在unity3d中动态创建easyAR的imageTarget
- 【c#】c#中 函数参数的注意事项
- 七月算法深度学习 第三期 学习笔记-第一节 数学基础
- 区间最多约数
- jQuery基础知识
- Java-ZipUtil工具类