leetcode 044 —— Wildcard Matching
来源:互联网 发布:数据库与数据挖掘 编辑:程序博客网 时间:2024/04/29 16:52
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") → falseisMatch("aa","aa") → trueisMatch("aaa","aa") → falseisMatch("aa", "*") → trueisMatch("aa", "a*") → trueisMatch("ab", "?*") → trueisMatch("aab", "c*a*b") → false
思路:
class Solution {public:bool isMatch(string s, string p) {int i = 0, j = 0;int star=-1;int ss=0;while (s[i]){if ((s[i] == p[j]) || (p[j] == '?')){i++;j++;continue;}if (p[j] == '*'){star = j++;ss = i;continue;}if (star>=0){j = star + 1;i = ++ss;continue;}return false;}while (p[j] == '*') j++;if (p[j])return false; //如果p[j]是null,那么!p[j]就是yes,如果是elsereturn true;}};
0 0
- leetcode 044 —— Wildcard Matching
- LeetCode——Wildcard Matching
- LeetCode 044 Wildcard Matching
- [LeetCode]044-Wildcard Matching
- LeetCode 044 Wildcard Matching
- LeetCode算法题——Wildcard Matching
- [leetcode] Wildcard matching——编程菜鸟们绝对值得一看
- Leetcode——44Wildcard Matching && 10 Regular Expression Matchi
- LeetCode: Wildcard Matching
- LeetCode : Wildcard Matching
- [LeetCode] Wildcard Matching - Iteratively
- leetcode 83: Wildcard Matching
- [Leetcode] Wildcard Matching
- [LeetCode]Wildcard Matching
- LeetCode-Wildcard Matching
- LeetCode -- Wildcard Matching
- LeetCode | Wildcard Matching
- Leetcode: Wildcard Matching
- 用Kibana和logstash快速搭建实时日志查询、收集与分析系统
- uva445string与字符串数组和单个字符逐个输入
- java中反射的小结
- TNS-12519(ORA-12519) 或 TNS-12516(ORA-12516)问题分析和处理
- c++ objective c 混合编程问题总结
- leetcode 044 —— Wildcard Matching
- 信用卡中银联、VISA、MasterCard的区别
- node模块的载入及机制
- 步进电机的加减速控制
- LeetCode Kth Smallest Element in a BST
- IBM软件测试理论——功能测试和回归测试
- 【JQuery】——JQuery的魅力
- HDU 1198——并查集
- leetcode[236]:Lowest Common Ancestor of a Binary Tree