LeetCode小结

RE-RegularExpresstion规则化表达

原题如下:

Given an input string (s) and a pattern (p), 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).

Note:

  • s could be empty and contains only lowercase letters a-z.
  • p could be empty and contains only lowercase letters a-z, and characters like . or *.

Example 1:

Input:
s = "aa"
p = "a"
Output: false
Explanation: "a" does not match the entire string "aa".

Example 2:

Input:
s = "aa"
p = "a*"
Output: true
Explanation: '*' means zero or more of the precedeng element, 'a'. Therefore, by repeating 'a' once, it becomes "aa".

Example 3:

Input:
s = "ab"
p = ".*"
Output: true
Explanation: ".*" means "zero or more (*) of any character (.)".

Example 4:

Input:
s = "aab"
p = "c*a*b"
Output: true
Explanation: c can be repeated 0 times, a can be repeated 1 time. Therefore it matches "aab".

Example 5:

Input:
s = "mississippi"
p = "mis*is*p*."
Output: false

对于匹配的理解:

Example1:P=a,意味着s中只能是a;

Example2:P=a*,意味着s可以是任意个a,包括0个a;

Example3:P='.*',*代表是对.的重复,而不是对aaaa的重复;

Example4:P='c*a*b',代表s可以是c任意个+a任意个+b,这里的任意个都可以包括0个,但必须有一个b;

Example5:P='mis*is*p*.',mis*是对s的任意重复,而不是对mis的任意重复。

阅读更多
个人分类: 编程 个人小结
上一篇练习题总结-字节对齐
下一篇&与&&
想对作者说点什么? 我来说一句

leetcode solution

2018年06月07日 1.15MB 下载

leetcode试题的答案

2018年01月14日 101KB 下载

leetbook书籍

2018年03月04日 1.26MB 下载

算法刷题LeetCode

2018年01月08日 837KB 下载

没有更多推荐了,返回首页

关闭
关闭