File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ Description :
66Source : https://leetcode.com/problems/regular-expression-matching/
77*******************************************/
88#include <stdbool.h>
9+
10+ //this is version is too slow repeating the calculation process too many times - try to use DP to replace it;
911bool match (char * s , char * p )
1012{
1113 return (* p == * s || (* p == '.' && * s != '\0' ));
@@ -22,10 +24,12 @@ bool isMatch(char* s, char* p)
2224 }
2325 else
2426 {
25- if (isMatch (s , p + 2 ))
27+ if (isMatch (s , p + 2 )) //repeat the previous character zero time;
2628 return true;
27- while (match (s , p ))
29+ while (match (s , p )) //repeat the previous at least one time unitl it fits;
2830 if (isMatch (++ s , p + 2 ))
2931 return true;
3032 }
3133}
34+
35+
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ char* simplifyPath(char* path)
3939 unitSize = cur - pre - 1 ;
4040 if (unitSize < 0 )//pre and cur point to the same position;
4141 continue ;
42- strncpy (unit , path + pre + 1 , unitSize );
42+ strncpy (unit , path + pre + 1 , unitSize );//cur - pre > 0 is ensured;
4343 unit [unitSize ] = '\0' ;
4444 pre = cur ;
4545 if (strcmp (unit , "." ) == 0 || strcmp (unit , "" ) == 0 ) //stay the same;
You can’t perform that action at this time.
0 commit comments