#排序词(permutation):两个字符串含有相同字符,但字符顺序不同。 from collections import defaultdict def is_permutation(str1, str2): if str1 is None or str2 is None: return False if len(str1) != len(str2): return False unq_s1 = defaultdict(int) unq_s2 = defaultdict(int) for c1 in str1: unq_s1[c1] += 1 for c2 in str2: unq_s2[c2] += 1 return unq_s1 == unq_s2