old_contents: """Leetcode 389. Find the Difference
  Easy
  
  URL: https://leetcode.com/problems/find-the-difference/
  
  Given two strings s and t which consist of only lowercase letters.
  
  String t is generated by random shuffling string s and then 
  add one more letter at a random position.
  
  Find the letter that was added in t.
  
  Example:
  Input:
  s = "abcd"
  t = "abcde"
  Output:
  e
  Explanation:
  'e' is the letter that was added.
  """
  
  class SolutionSortIter(object):
      def findTheDifference(self, s, t):
          """
          :type s: str
          :type t: str
          :rtype: str
  
          Time complexity: O(n*logn).
          Space complexity: O(n).
          """
          s_ls = list(s)
          t_ls = list(t)
          s_ls.sort()
          t_ls.sort()
  
          for i, c in enumerate(s_ls):
              if c != t_ls[i]:
                  return t_ls[i]
  
          return t_ls[-1]
  
  
  class SolutionDict(object):
      def findTheDifference(self, s, t):
          """
          :type s: str
          :type t: str
          :rtype: str
  
          Time complexity: O(n).
          Space complexity: O(n).
          """
          from collections import defaultdict
          char_nums = defaultdict(int)
  
          # Iterate char in s and increment its counter.
          for c in s:
              char_nums[c] += 1
  
          # Iterate char in t and decrement its counter.
          for c in t:
              # If new char in t or its counter = 0, obtain the difference.
              if char_nums.get(c, 0) == 0:
                  return c
              else:
                  char_nums[c] -= 1
          
  
  def main():
      # Output: e
      s = "abcd"
      t = "abcde"
      print SolutionSortIter().findTheDifference(s, t)
      print SolutionDict().findTheDifference(s, t)
  
      # Output: e
      s = ""
      t = "e"
      print SolutionSortIter().findTheDifference(s, t)
      print SolutionDict().findTheDifference(s, t)
  
  
  if __name__ == '__main__':
      main()
  
new_contents: """Leetcode 389. Find the Difference
  Easy
  
  URL: https://leetcode.com/problems/find-the-difference/
  
  Given two strings s and t which consist of only lowercase letters.
  
  String t is generated by random shuffling string s and then 
  add one more letter at a random position.
  
  Find the letter that was added in t.
  
  Example:
  Input:
  s = "abcd"
  t = "abcde"
  Output:
  e
  Explanation:
  'e' is the letter that was added.
  """
  
  class SolutionSortIter(object):
      def findTheDifference(self, s, t):
          """
          :type s: str
          :type t: str
          :rtype: str
  
          Time complexity: O(n*logn).
          Space complexity: O(n).
          """
          s_ls = list(s)
          t_ls = list(t)
          s_ls.sort()
          t_ls.sort()
  
          for i, c in enumerate(s_ls):
              if c != t_ls[i]:
                  return t_ls[i]
  
          return t_ls[-1]
  
  
  class SolutionDict(object):
      def findTheDifference(self, s, t):
          """
          :type s: str
          :type t: str
          :rtype: str
  
          Time complexity: O(n).
          Space complexity: O(n).
          """
          from collections import defaultdict
          char_nums = defaultdict(int)
  
          # Iterate char in s and increment its counter.
          for c in s:
              char_nums[c] += 1
  
          # Iterate char in t and decrement its counter.
          for c in t:
              # If new char in t or its counter = 0, obtain the difference.
              if char_nums.get(c, 0) == 0:
                  return c
              else:
                  char_nums[c] -= 1
  
  
  class SolutionOrdDiff(object):
      def findTheDifference(self, s, t):
          """
          :type s: str
          :type t: str
          :rtype: str
  
          Time complexity: O(n).
          Space complexity: O(1).
          """
          ord_diff = 0
  
          # Decrement by s's char ord.
          for c in s:
              ord_diff -= ord(c)
  
          # Increment by t's char ord.
          for c in t:
              ord_diff += ord(c)
  
          return chr(ord_diff)
          
  
  def main():
      # Output: e
      s = "abcd"
      t = "abcde"
      print SolutionSortIter().findTheDifference(s, t)
      print SolutionDict().findTheDifference(s, t)
      print SolutionOrdDiff().findTheDifference(s, t)
  
      # Output: a
      s = ""
      t = "a"
      print SolutionSortIter().findTheDifference(s, t)
      print SolutionDict().findTheDifference(s, t)
      print SolutionOrdDiff().findTheDifference(s, t)
  
  
  if __name__ == '__main__':
      main()
  
subject: Complete ord diff sol