-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathent01.py
46 lines (33 loc) · 785 Bytes
/
ent01.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
def one_edit_away(s1,s2):
if s1 == s2:
return True
elif len(s1) == len(s2):
return check_replace(s1,s2)
elif abs(len(s1)-len(s2)) == 1:
if len(s1) > len(s2):
return check_insert(s1,s2)
else:
return check_insert(s2,s1)
else:
return False
def check_replace(s1,s2):
counter = 0
for i in range(len(s1)):
if s1[i] != s2[i]:
counter+=1
if counter > 1:
return False
return True
def check_insert(s1,s2):
j=0
for i in range(len(s1)):
if i==len(s2)-1:
return True
elif s1[i] != s2[j] :
j-=1
j+=1
if i!=j:
print(i,j)
return False
else:
return True