lc10. Regular Expression Matching
Contents
Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where:
'.'Matches any single character.'*'Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
Example 1:
|
|
Example 2:
|
|
Example 3:
|
|
Constraints:
1 <= s.length <= 201 <= p.length <= 30scontains only lowercase English letters.pcontains only lowercase English letters,'.', and'*'.- It is guaranteed for each appearance of the character
'*', there will be a previous valid character to match.
解题思路
手写最简单的正则表达式函数,判断s是否符合p的正则规则。
初始思路
用两个指针分别读取s和p的头,按照规则依次匹配。确保两个指针可以在满足规则的前提下都移动到s和p的尾端。
进阶思路
动态规划。类似于两个序列做比对,只要可以完全alignment上就OK。

|
|