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.

Revisions

  1. SantonyChoi revised this gist May 6, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions strings.py
    Original file line number Diff line number Diff line change
    @@ -10,8 +10,10 @@ def equalsWhenOneCharRemoved(x, y):
    if has_removed:
    return False
    elif len(x) > len(y):
    has_removed = True
    ix += 1
    else:
    has_removed = True
    iy += 1

    ix += 1
  2. SantonyChoi revised this gist May 6, 2019. 1 changed file with 15 additions and 14 deletions.
    29 changes: 15 additions & 14 deletions strings.py
    Original file line number Diff line number Diff line change
    @@ -2,18 +2,19 @@ def equalsWhenOneCharRemoved(x, y):
    if abs(len(x) - len(y)) != 1:
    return False

    return compareEachChars(x, y, False)
    has_removed = False
    ix, iy = 0, 0

    while ix < len(x) and iy < len(y):
    if x[ix] != y[iy]:
    if has_removed:
    return False
    elif len(x) > len(y):
    ix += 1
    else:
    iy += 1

    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)
    ix += 1
    iy += 1

    return True
  3. SantonyChoi created this gist May 6, 2019.
    19 changes: 19 additions & 0 deletions strings.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    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)