LyWang

String_comparison

Nov 18th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. class Solution:
  2.     """
  3.    @param A: A string
  4.    @param B: A string
  5.    @return: if string A contains all of the characters in B return true else return false
  6.    """
  7.     def compareStrings(self, A, B):
  8.         # write your code here
  9.         la = len(A)
  10.         lb = len(B)
  11.         if la < lb:
  12.             return False
  13.         if lb==0:
  14.             return True
  15.         sA = sorted (A)
  16.         sB = sorted (B)
  17.         i = 0
  18.         j = 0
  19.         while True:
  20.             if j>(lb-1):
  21.                 return True
  22.             if i>(la-1):
  23.                 return False
  24.             if sA[i]==sB[j]:
  25.                 i+=1
  26.                 j+=1
  27.             else:
  28.                if sA[i] > sB[j]:
  29.                    return False
  30.                else:
  31.                    i+=1
Add Comment
Please, Sign In to add comment