We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8fc8681 commit aa3e40eCopy full SHA for aa3e40e
Scripts/Edit Distance.py
@@ -12,7 +12,7 @@ def calculate_distance(s1,s2):
12
13
for i in range(row):
14
for j in range(col):
15
- #either i or j is 0
+ #either i or j is 0 (for converting to Null)
16
if i==0:
17
dp_array[i][j] = j
18
continue
@@ -24,10 +24,12 @@ def calculate_distance(s1,s2):
24
if s1[i-1]!=s2[j-1]:
25
#Get min from updown L shape ([i-1][j], [i-1][j-1], [i][j-1]) and add 1 (performing operation)
26
dp_array[i][j] = min(dp_array[i-1][j],dp_array[i][j-1],dp_array[i-1][j-1]) +1
27
+
28
#Same chars, so no need for operation, hence take previous row:col values
29
else:
30
dp_array[i][j]=dp_array[i-1][j-1]
31
32
+ #return right-bottom-most value
33
return dp_array[row-1][col-1]
34
35
#main
0 commit comments