Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def equalsWhenOneCharRemoved(x, y):
- # Can't be different in length by more than 1
- if (abs(len(x) - len(y)) > 1):
- return False
- # Iterate through X and Y together
- diffFound = 0;
- lenX = len(x)
- lenY = len(y)
- for i in range(max(lenX, lenY)):
- # If we have reached the end of either string, break
- if (i >= lenX - 1 or i >= lenY -1):
- break
- # If they are different at an index, we add a difference
- if (x[i] != y[i]):
- diffFound += 1
- # If there is more than one difference, they are not similar enough
- if (diffFound > 1):
- return False
- # If we get here, check the number of differences is less than 1
- return diffFound <= 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement