Skip to content

Commit 72b6072

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent c18a9ef commit 72b6072

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

strings/min_cost_string_conversion.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
def compute_transform_tables(s1, s2, insert_cost, delete_cost, replace_cost, swap_cost, ignore_case=False):
1+
def compute_transform_tables(
2+
s1, s2, insert_cost, delete_cost, replace_cost, swap_cost, ignore_case=False
3+
):
24
if ignore_case:
35
s1, s2 = s1.lower(), s2.lower()
46

@@ -12,17 +14,17 @@ def compute_transform_tables(s1, s2, insert_cost, delete_cost, replace_cost, swa
1214
# Initialize base cases
1315
for i in range(1, m + 1):
1416
dp[i][0] = i * delete_cost
15-
op[i][0] = 'D' + s1[i - 1]
17+
op[i][0] = "D" + s1[i - 1]
1618
for j in range(1, n + 1):
1719
dp[0][j] = j * insert_cost
18-
op[0][j] = 'I' + s2[j - 1]
20+
op[0][j] = "I" + s2[j - 1]
1921

2022
# Fill DP tables
2123
for i in range(1, m + 1):
2224
for j in range(1, n + 1):
2325
if s1[i - 1] == s2[j - 1]:
2426
dp[i][j] = dp[i - 1][j - 1]
25-
op[i][j] = 'C' + s1[i - 1]
27+
op[i][j] = "C" + s1[i - 1]
2628
else:
2729
replace = dp[i - 1][j - 1] + replace_cost
2830
insert = dp[i][j - 1] + insert_cost
@@ -33,12 +35,10 @@ def compute_transform_tables(s1, s2, insert_cost, delete_cost, replace_cost, swa
3335
dp[i][j] = min_cost
3436

3537
if min_cost == replace:
36-
op[i][j] = 'R' + s2[j - 1]
38+
op[i][j] = "R" + s2[j - 1]
3739
elif min_cost == insert:
38-
op[i][j] = 'I' + s2[j - 1]
40+
op[i][j] = "I" + s2[j - 1]
3941
else:
40-
op[i][j] = 'D' + s1[i - 1]
42+
op[i][j] = "D" + s1[i - 1]
4143

4244
return dp, op
43-
44-

0 commit comments

Comments
 (0)