Created
January 11, 2020 07:41
-
-
Save hoyajigi/3cdbf57581fa220362d1ec8d3a094543 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def equalsWhenOneCharRemoved(x, y): | |
if abs(len(x) - len(y)) != 1: | |
return False | |
if len(x) > len(y): | |
x, y = y, x | |
i = padding = 0 | |
while i < len(x) and i + padding < len(y): | |
if x[i] == y[i + padding]: | |
i = i + 1 | |
else: | |
padding += 1 | |
if i == len(x) and padding < 2: | |
return True | |
return False | |
assert equalsWhenOneCharRemoved("x", "y") is False | |
assert equalsWhenOneCharRemoved("x", "XX") is False | |
assert equalsWhenOneCharRemoved("yy", "yx") is False | |
assert equalsWhenOneCharRemoved("abcd", "abxcd") is True | |
assert equalsWhenOneCharRemoved("xyz", "xz") is True | |
assert equalsWhenOneCharRemoved("xyz", "xy") is True | |
assert equalsWhenOneCharRemoved("yxz", "xz") is True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment