Set是一个很好的方法,因为它对变量进行排序,这似乎是你的目标。 {z,y,x} 是 {0,1,3} 不管参数的顺序如何。
{z,y,x}
{0,1,3}
>>> ["cdef"[i] for i in {z,x,y}] ['c', 'd', 'f']
这样,整个解是O(n)。