Skip to content

Commit e400382

Browse files
committed
SimplifyPath corrected
1 parent 71d1093 commit e400382

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

LuoSonglei/week-3/RegxMatching.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Description :
66
Source : 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;
911
bool 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+

LuoSonglei/week-3/SimplifyPath.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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;

0 commit comments

Comments
 (0)