由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问一道LeeCode题目: regular expression matching
相关主题
Wildcard Matching 和 Regular Expression Matching 区别是什么请问LeetCode Wild Matching的贪心解法,为什么只需要记录最后一个*?
问一道Leetcode的题目。带'+'的regular expression matching 求解法
Leetcode-010: Regular Expression Match (DP Solution)Leetcode regular expression 问题
Leetcode regular expression matching那道题java没有指针真麻烦
isMatch("ab", ".*") → true 为什么是true???Wildcard Matching题求助
leetcode 上面的Regular Expression Matching如果面试遇到 regular expression match 或者 wildcard matching之类的
问一下 leetcode里面的 regular expression matching问个google面试题
Regular Expression Matching 问题请教。。关于wildcard match和regex match的一个问题
相关话题的讨论汇总
话题: ismatch话题: true话题: aa话题: matching话题: matches
进入JobHunting版参与讨论
1 (共1页)
H*****l
发帖数: 1257
1
题目在下面。
两个test case看起来是互相矛盾的,搞不清楚规则:
input expected
"ab", ".*c" false
input expected
"ab", ".*" true
我觉得这两个都应该是true才对啊。。。
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
t********5
发帖数: 522
2
第一个是0-n个任意字符然后以c结尾
ab不是c结尾 所以false
H*****l
发帖数: 1257
3
那这样的话,example的第一个怎么解释呢?

【在 t********5 的大作中提到】
: 第一个是0-n个任意字符然后以c结尾
: ab不是c结尾 所以false

t********5
发帖数: 522
4
因为aa !=== a 所以是false
第一个例子没有使用通配符 必须要完全匹配才行
H*****l
发帖数: 1257
5
难道是说,要p能符合规则的转换成s ? 而不是p的一部分能符合规则的转换成s就可以?
那下面这个,为什么是true?
isMatch("aab", "c*a*b") ? true

【在 t********5 的大作中提到】
: 因为aa !=== a 所以是false
: 第一个例子没有使用通配符 必须要完全匹配才行

g****o
发帖数: 547
6
同问
好像跟 wildcard mathching 一题没区别
但那题
isMatch("aab", "c*a*b") ? false
g****o
发帖数: 547
7
知道为什么了
wildcard mathching
'*' Matches any sequence of characters (including the empty sequence).
"c*"一定是以c开头的字符串
所以isMatch("aab", "c*a*b") ? false
regular expression matching
'*' Matches zero or more of the preceding element.
"c*"可以是"","c","cc","ccc"...
所以isMatch("aab", "c*a*b") ? true

【在 g****o 的大作中提到】
: 同问
: 好像跟 wildcard mathching 一题没区别
: 但那题
: isMatch("aab", "c*a*b") ? false

t********5
发帖数: 522
8
可以这么说 或者说是 s 符合 p 的约束
这个你看一下基本的正则表达式概念就会很清楚~ 可以趁机学一下perl然后顺带学正则
最后的例子 c*a*b 表示可以0到多个c 后面跟0到多个a 最后以一个b结尾
所以aab符合这个约束 因为是 0个c 2个a 以1个b结尾

以?

【在 H*****l 的大作中提到】
: 难道是说,要p能符合规则的转换成s ? 而不是p的一部分能符合规则的转换成s就可以?
: 那下面这个,为什么是true?
: isMatch("aab", "c*a*b") ? true

H*****l
发帖数: 1257
9
我终于知道为什么了。。。
原来c*在一起表示0到无数个c
我一开始以为c和*是孤立的,c表示一个c,*单独表示0到无数个c

【在 t********5 的大作中提到】
: 可以这么说 或者说是 s 符合 p 的约束
: 这个你看一下基本的正则表达式概念就会很清楚~ 可以趁机学一下perl然后顺带学正则
: 最后的例子 c*a*b 表示可以0到多个c 后面跟0到多个a 最后以一个b结尾
: 所以aab符合这个约束 因为是 0个c 2个a 以1个b结尾
:
: 以?

1 (共1页)
进入JobHunting版参与讨论
相关主题
关于wildcard match和regex match的一个问题isMatch("ab", ".*") → true 为什么是true???
leetcode valid numberleetcode 上面的Regular Expression Matching
请问大牛们关于Regular expression matching问一下 leetcode里面的 regular expression matching
一道算法题Regular Expression Matching 问题请教。。
Wildcard Matching 和 Regular Expression Matching 区别是什么请问LeetCode Wild Matching的贪心解法,为什么只需要记录最后一个*?
问一道Leetcode的题目。带'+'的regular expression matching 求解法
Leetcode-010: Regular Expression Match (DP Solution)Leetcode regular expression 问题
Leetcode regular expression matching那道题java没有指针真麻烦
相关话题的讨论汇总
话题: ismatch话题: true话题: aa话题: matching话题: matches