3 回答

TA贡献1804条经验 获得超2个赞
O(N)
def compare(s, t): return Counter(s) == Counter(t)
O(n对数n)
def compare(s, t): return sorted(s) == sorted(t)
O(n*n)
def compare(s, t): t = list(t) # make a mutable copy try: for elem in s: t.remove(elem) except ValueError: return False return not t

TA贡献1995条经验 获得超2个赞
Counter
sorted(a) == sorted(b)
id()
sorted(a, key=id) == sorted(b, key==id)
key=
repr()
repr()
sorted(a, key=repr) == sorted(b, key==repr)
__lt__()
key=
__hash__()
Counter
添加回答
举报