擅长:python、mysql、java
<p>稍微快一点的实现版本(如果您知道大多数情侣列表的长度不同):</p>
<pre><code>def checkEqual(L1, L2):
return len(L1) == len(L2) and sorted(L1) == sorted(L2)
</code></pre>
<p>比较:</p>
<pre><code>>>> timeit(lambda: sorting([1,2,3], [3,2,1]))
2.42745304107666
>>> timeit(lambda: lensorting([1,2,3], [3,2,1]))
2.5644469261169434 # speed down not much (for large lists the difference tends to 0)
>>> timeit(lambda: sorting([1,2,3], [3,2,1,0]))
2.4570400714874268
>>> timeit(lambda: lensorting([1,2,3], [3,2,1,0]))
0.9596951007843018 # speed up
</code></pre>