Skip to content

Commit aa3e40e

Browse files
+edit distance problem
1 parent 8fc8681 commit aa3e40e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Scripts/Edit Distance.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def calculate_distance(s1,s2):
1212

1313
for i in range(row):
1414
for j in range(col):
15-
#either i or j is 0
15+
#either i or j is 0 (for converting to Null)
1616
if i==0:
1717
dp_array[i][j] = j
1818
continue
@@ -24,10 +24,12 @@ def calculate_distance(s1,s2):
2424
if s1[i-1]!=s2[j-1]:
2525
#Get min from updown L shape ([i-1][j], [i-1][j-1], [i][j-1]) and add 1 (performing operation)
2626
dp_array[i][j] = min(dp_array[i-1][j],dp_array[i][j-1],dp_array[i-1][j-1]) +1
27+
2728
#Same chars, so no need for operation, hence take previous row:col values
2829
else:
2930
dp_array[i][j]=dp_array[i-1][j-1]
3031

32+
#return right-bottom-most value
3133
return dp_array[row-1][col-1]
3234

3335
#main

0 commit comments

Comments
 (0)