Determine if two strings are anagrams

 

'''

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)
 '''
View Code

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325299568&siteId=291194637