Skip to content

Instantly share code, notes, and snippets.

@jykim16
Created January 17, 2020 07:02
Show Gist options
  • Save jykim16/1f5b231abe291aaf402770adcc78cc47 to your computer and use it in GitHub Desktop.
Save jykim16/1f5b231abe291aaf402770adcc78cc47 to your computer and use it in GitHub Desktop.
def equalsWhenOneCharRemoved(x, y):
lengthDiff = len(y) - len(x)
if not (lengthDiff == 1 or lengthDiff == -1):
return False
for pointer in range(len(x)):
if x[pointer] == y[pointer]:
continue
else:
if x[pointer:] == y[pointer+1:]:
return True
elif x[pointer+1:] == y[pointer:]:
return True
return False
return True
assert equalsWhenOneCharRemoved("x", "y") is False
assert equalsWhenOneCharRemoved("x", "XX") is False
assert equalsWhenOneCharRemoved("yy", "yx") is False
assert equalsWhenOneCharRemoved("helloworld", "helloworldzz") is False
assert equalsWhenOneCharRemoved("abcd", "abxcd") is True
assert equalsWhenOneCharRemoved("xyz", "xz") is True
assert equalsWhenOneCharRemoved("helloworld", "helloworlds") is True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment