''' https://www.cnblogs.com/tanfd/p/6099429.html Determine whether two characters are ectopic characters: For example, abcda is the ectopic character of aabcd ''' #Method 1: print(sorted( ' abcda ' )==sorted( ' aabcd ' )) ''' efficiency O( NlogN) ' '' #Method 2: The idea of hashing. Use ord to become asci code a='abcda' b='aabcd' d=[0]*256 for i in range(len(a)): d[ord(a[i])] += 1 d[ord(b[i])] -= 1 print(d ==[ 0 ]* 256 ) ''' Efficiency O(N) '''