10. Regular Expression Matching
Description
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 lettersa-z
.p
could be empty and contains only lowercase lettersa-z
, and characters like.
or*
.
Constraints
Approach
Links
GeeksforGeeks
Examples
Input:
s = "aa"
p = "a"
Output: false
Explanation: "a" does not match the entire string "aa".
Solutions
/**
* Time complexity :
* Space complexity :
*/
class Solution {
public boolean isMatch(String s, String p) {
if(s == null) return false;
return s.matches(p);
}
}
Follow up
Last updated
Was this helpful?