File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed
Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,26 @@ void main(List<String> args) {
1313}
1414
1515bool isMatch (String s, String p) {
16- final RegExp regExp = RegExp (p.replaceAll ('*' , '^g\. *' ).replaceAll ('?' , '^g\. ?' ));
17- print (regExp.stringMatch (s));
18- return regExp.stringMatch (s) == s;
16+ if (p.replaceAll ("*" , "" ).length > s.length) return false ;
17+
18+ List <bool > flags = List .generate (s.length + 1 , (index) => false );
19+ flags.first = true ;
20+ for (int i = 1 ; i < s.length; ++ i) {
21+ flags[i] = false ;
22+ }
23+
24+ for (int i = 1 ; i <= p.length; ++ i) {
25+ String char = p[i - 1 ];
26+ if (char == '*' ) {
27+ for (int j = 1 ; j <= s.length; ++ j) {
28+ flags[j] = flags[j - 1 ] || flags[j];
29+ }
30+ } else {
31+ for (int j = s.length; j >= 1 ; -- j) {
32+ flags[j] = flags[j - 1 ] && (char == '?' || char == s[j - 1 ]);
33+ }
34+ }
35+ flags[0 ] = flags[0 ] && char == '*' ;
36+ }
37+ return flags[s.length];
1938}
You can’t perform that action at this time.
0 commit comments