old_contents: # Time:  O(m + n)
  # Space: O(1)
  #
  # Given two strings S and T, determine if they are both one edit distance apart.
  #
  
  class Solution(object):
      def isOneEditDistance(self, s, t):
          """
          :type s: str
          :type t: str
          :rtype: bool
          """
          m, n = len(s), len(t)
          if m > n:
              return self.isOneEditDistance(t, s)
          if n - m > 1:
              return False
          
          i, shift = 0, n - m
          while i < m and s[i] == t[i]:
              i += 1
          if shift == 0:
              i += 1
          while i < m and s[i] == t[i + shift]:
              i += 1
              
          return i == m
      
  if __name__ == "__main__":
      print Solution().isOneEditDistance("teacher", "acher")
  
new_contents: # Time:  O(m + n)
  # Space: O(1)
  #
  # Given two strings S and T, determine if they are both one edit distance apart.
  #
  
  class Solution(object):
      def isOneEditDistance(self, s, t):
          """
          :type s: str
          :type t: str
          :rtype: bool
          """
          m, n = len(s), len(t)
          if m > n:
              return self.isOneEditDistance(t, s)
          if n - m > 1:
              return False
          
          i, shift = 0, n - m
          while i < m and s[i] == t[i]:
              i += 1
          if shift == 0:
              i += 1
          while i < m and s[i] == t[i + shift]:
              i += 1
              
          return i == m
  
     
  if __name__ == "__main__":
      print Solution().isOneEditDistance("teacher", "acher")
  
subject: Update one-edit-distance.py