-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_operation_for_two_string.py
53 lines (41 loc) · 1.35 KB
/
delete_operation_for_two_string.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from multiprocessing import cpu_count
#a naive solution that is not working properly
def minDistance(word1, word2) :
def sliding_window(word1, word2):
n = len(word1)
a = word1
b = word2
#initialize the sliding window
count = len(a)
end = 0
for end in range(n):
start = 0
a = word1
a = a.replace(a[end:end+1], '', 1)
print(a)
print(start)
while start < n:
b = word2
b = b.replace(b[start:start+1], '', 1)
print (b, start)
if b == a:
count = min(count, end - start+1)
# print(count)
else:
start+= 1
return count
if len(word1) > len(word2):
return len(word1) - len(word2)
elif len(word1) < len(word2):
return len(word2) - len(word1)
else:
return sliding_window(word1, word2)
a = "sea"
b = "ate"
print(minDistance(a,b))
# if len(word1) == len(word2):
# for char in range(len(word1)):
# if word1[char] not in word2:
# count += 1
# # print (word1[char])
# return count * 2