LeetCode OJ:Regular Expression Matching(正则表达式匹配)
Implement regular expression matching with support for '.' and '*'.
'.' Matches any single character.
'*' Matches zero or more of the preceding element. 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", "a*") → true
isMatch("aa", ".*") → true
isMatch("ab", ".*") → true
isMatch("aab", "c*a*b") → true
正则表达式的匹配,注意*代表的不是任意的字符,而是0个或者任意多个前向的字符,代码如下:
class Solution {
public:
bool isMatch(string s, string p) {
if(p.size() == ) return s.size() == ;
if(p[] != '*'){
if(s.size() != && (p[] == s[] || p[] == '.'))
return isMatch(s.substr(), p.substr());
return false;
}else{
while(s.size() != &&(s[] == p[] || p[] == '.')){//模式串匹配0个或者更多的字符
if(isMatch(s, p.substr()))
return true;
s = s.substr();
}
return isMatch(s, p.substr());
}
}
};
LeetCode OJ:Regular Expression Matching(正则表达式匹配)的更多相关文章
- [LeetCode] 10. Regular Expression Matching 正则表达式匹配
Given an input string (s) and a pattern (p), implement regular expression matching with support for ...
- [LeetCode]10. Regular Expression Matching正则表达式匹配
Given an input string (s) and a pattern (p), implement regular expression matching with support for ...
- [LeetCode] Regular Expression Matching 正则表达式匹配
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- [leetcode]10. Regular Expression Matching正则表达式的匹配
Given an input string (s) and a pattern (p), implement regular expression matching with support for ...
- 010 Regular Expression Matching 正则表达式匹配
Implement regular expression matching with support for '.' and '*'.'.' Matches any single character. ...
- 10. Regular Expression Matching正则表达式匹配
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- leetcode 10 Regular Expression Matching(简单正则表达式匹配)
最近代码写的少了,而leetcode一直想做一个python,c/c++解题报告的专题,c/c++一直是我非常喜欢的,c语言编程练习的重要性体现在linux内核编程以及一些大公司算法上机的要求,pyt ...
- LeetCode (10): Regular Expression Matching [HARD]
https://leetcode.com/problems/regular-expression-matching/ [描述] Implement regular expression matchin ...
- [LeetCode][Python]Regular Expression Matching
# -*- coding: utf8 -*-'''https://oj.leetcode.com/problems/regular-expression-matching/ Implement reg ...
- 【leetcode】Regular Expression Matching (hard) ★
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
随机推荐
- windows上使用clang编译程序
环境:windows7,64位 1.下载并安装llvm,安装包里除了llvm,也有clang: http://releases.llvm.org/5.0.0/LLVM-5.0.0-win64.exe ...
- pyinstaller 打包生成的exe文件,在其他电脑上报错
解决方法: 1.第一种情况,在打包的时候不要加参数-w,看一下执行exe文件后出现的报错再看下一步的行动 2.应该是需要装一个VC 2015 x64(下载地址:https://www.microsof ...
- python3_json模块使用与字符编码问题
序列化:将对象的状态信息转换为可以存储或可以通过网络传输的过程,传输的格式可以是json,xml. 反序列化:就是从存储区域(json,xml)读取反序列化对象的状态,重新创建该对象 Json:一种轻 ...
- Mac OS下开启自带的apache服务
Apache路径 /etc/apache2/ [root@GGs-MacBook-Pro:/Volumes/SSD/blog#cd /etc/apache2/ [root@GGs-MacBook-Pr ...
- 【c++ primer, 5e】函数重载
[函数重载] Java中的重载一般是指重载构造器,或是子类覆写父类的方法:C++中的重载稍微复杂一些. 定义重载函数 典型的数据库应用. Record lookup(const Account& ...
- J2Cache 和普通缓存框架有何不同,它解决了什么问题?
不少人看到 J2Cache 第一眼时,会认为这就是一个普普通通的缓存框架,和例如 Ehcache.Caffeine .Spring Cache 之类的项目没什么区别,无非是造了一个新的轮子而已.事实上 ...
- DNSmasq安装配置
dns安装配置yum -y install dnsmasq dns配置文件vi /etc/dnsmasq.confresolv-file=/etc/resolv.dnsmasq.confaddn-ho ...
- LSTM java 实现
由于实验室事情缘故,需要将Python写的神经网络转成Java版本的,但是python中的numpy等啥包也不知道在Java里面对应的是什么工具,所以索性直接寻找一个现成可用的Java神经网络框架,于 ...
- 20145327高晨 实验一 "Java开发环境的熟悉"
实验一 Java开发环境的熟悉(Linux + Eclipse) (Windows + IDEA) 实验内容:实现Fibonacci数列功能,并进行测试. 实验步骤: Fibonacci数列(斐波拉契 ...
- 51Nod 1521 一维战舰
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1521 思路:先计算出一开始最多能放多少艘战舰,然后每次输入一个点后,找到 ...