Problem Statement
For example, "01*00*" describes all strings that start with '0', then have zero or more '1's, then have a '0', and then have zero or more '0's. The shortest string that satisfies this description is "00".
Create a class Regulars that contains a method stringCt that is given a simple regular expression regex and an int maxLen and that returns the number of distinct strings that satisfy regex and contain between 0 and maxLen characters, inclusive.
Definition
- Class:
- Regulars
- Method:
- stringCt
- Parameters:
- String, int
- Returns:
- long
- Method signature:
- long stringCt(String regex, int maxLen)
- (be sure your method is public)
Constraints
- regex will contain between 1 and 50 characters, inclusive.
- Each character in regex will be '0' (zero), '1' (one), or '*'.
- Each '*' in regex will be immediately preceded by '0' or '1'.
- maxLen will be between 1 and 50, inclusive.
Examples
"0*"
5
Returns: 6
"","0","00","000","0000","00000" are the legal strings."01*1*1*"
3
Returns: 3
"0","01","011" are the legal strings."0*1*0*1*0*1*0*1*0*1*0*1*0*1*0*1*0*1*0*1*0*1*0*1*0*"
50
Returns: 1125899906842623