LeetCode之Regular Expression Matching
来源:互联网 发布:淘宝靠谱的宠物店 编辑:程序博客网 时间:2024/06/05 18:04
/*这道题最关键的是理解题意。最重要的是:当一个字母后面跟着字符'*',表示这个字符重复0次,1次,...,n次。所以在判断字符串是否匹配时,需要看接下来p的字符是否为'*'字符。分两种情况处理*///方法一:递归法class Solution {public: bool isMatch(string s, string p) { if(p.empty()) return s.empty(); return is_match(s, p, 0, 0); } bool is_match(const string &s, const string &p, int idx_s, int idx_p){ if(idx_p == p.size()) return idx_s == s.size(); if(idx_p + 1 == p.size()) return idx_s+1 == s.size() && (p[idx_p] == s[idx_s] || p[idx_p] == '.'); if(p[idx_p+1] != '*'){ if(p[idx_p] == s[idx_s] || (p[idx_p] == '.' && idx_s < s.size())){ return is_match(s, p, idx_s+1, idx_p+1); } else return false; } while(p[idx_p] == s[idx_s] || (p[idx_p] == '.' && idx_s < s.size())){ if(is_match(s, p, idx_s, idx_p+2)) return true; ++idx_s; } return is_match(s, p, idx_s, idx_p+2); }};
0 0
- leetcode之Regular Expression Matching
- LeetCode之Regular Expression Matching
- 【Leetcode】之Regular Expression Matching
- LeetCode: Regular Expression Matching
- LeetCode: Regular Expression Matching
- leetcode Regular Expression Matching
- [Leetcode] Regular Expression Matching
- [LeetCode]Regular Expression Matching
- LeetCode-Regular Expression Matching
- Regular Expression Matching LeetCode
- LeetCode | Regular Expression Matching
- LeetCode: Regular Expression Matching
- Leetcode: Regular Expression Matching
- [LeetCode] Regular Expression matching
- [LeetCode] Regular Expression Matching
- LeetCode Regular Expression Matching
- leetcode Regular Expression Matching
- leetcode: Regular Expression Matching
- 基因组与数据整合:DNA应用开发正在临近
- autotools使用(自动生成makefile)
- 第9课 u-boot 分析 初探
- androidstudio 快捷键大全
- android 数据库sqlite的使用方法
- LeetCode之Regular Expression Matching
- c/c++内存机制
- android关于下拉刷新列表的使用列表
- Android实践-使用ViewPager和Fragment实现带Tab导航条的仿新闻类页面
- 20150624_OC之代理及反向代理的简单例子
- mysql 5.6 时间函数的变化 FROM_UNIXTIME CURRENT_TIMESTAMP
- .NET 获取类内成员的名称,以字符串形式显示
- js取得table中td值的问题
- java修饰符