-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoneaway.py
31 lines (29 loc) · 829 Bytes
/
oneaway.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
s1 = input("Enter first String:")
s2 = input("Enter second string:")
def oneaway(s1,s2):
if (abs(len(s1)-len(s2))>1):
return False
if len(s1)>len(s2):
largerString = s1
smallerString = s2
else:
largerString = s2
smallerString = s1
mismatchFound = False
sIndex=0
lIndex=-1
sameLength = False
if len(s1)==len(s2):
sameLength = True
while sIndex<len(smallerString):
lIndex = lIndex + 1
if(smallerString[sIndex]!= largerString[lIndex]):
if not mismatchFound :
mismatchFound = True
if not sameLength:
continue
else:
return False
sIndex = sIndex + 1
return True
print("Strings are one character away :",oneaway(s1,s2))