Skip to content

Commit

Permalink
FIX: fix off-by-one bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tacaswell committed Jul 6, 2015
1 parent ddbc174 commit 3743f6e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions exercises/03-wrapping/01-levenshtein/levenshtein.c
Expand Up @@ -2,6 +2,7 @@
#include <string.h>
#include <stdlib.h>


#define MIN2(a, b) ((a) < (b) ? (a) : (b))
#define MIN3(a, b, c) (MIN2((c), MIN2((a), (b))))

Expand All @@ -15,7 +16,7 @@ int levenshtein_dist(const char *s, const char *t)
for (i=1; i<m+1; ++i)
d[i*(n+1)] = i;

for (j=1; j<n+1; ++j)
for (j=0; j<n+1; ++j)
d[j] = j;

for (j=1; j<n+1; ++j) {
Expand All @@ -32,10 +33,12 @@ int levenshtein_dist(const char *s, const char *t)
}
}

int out = d[m * (n+1) + n];

if(d)
free(d);
return out;

return d[m * (n+1) + n];

fail:
return -1;
Expand Down

0 comments on commit 3743f6e

Please sign in to comment.