Skip to content

Instantly share code, notes, and snippets.

@SantonyChoi
Last active May 6, 2019 07:38
Show Gist options
  • Save SantonyChoi/c3d957b74d65a41d0a69052a814e9431 to your computer and use it in GitHub Desktop.
Save SantonyChoi/c3d957b74d65a41d0a69052a814e9431 to your computer and use it in GitHub Desktop.
def equalsWhenOneCharRemoved(x, y):
if abs(len(x) - len(y)) != 1:
return False
return compareEachChars(x, y, False)
def compareEachChars(a, b, has_removed):
if not a or not b:
return True
if a[0] != b[0]:
if has_removed:
return False
elif len(a) > len(b):
return compareEachChars(a[1:], b, True)
else:
return compareEachChars(a, b[1:], True)
else:
return compareEachChars(a[1:],b[1:], has_removed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment