Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
你有一组洗过的牌。您必须重新订购它们。
为此,您可以根据其价值(杰克 = 11,皇后 - 12)等及其套件(红心 = 0,梅花 = 1 ...)为每张牌分配一个数字。每张卡通过公式(14 *套件)+值获得唯一编号。然后你有一个包含 52 个元素的空数组,只需将每张卡片放在正确的位置。这非常快 - 大 o 将是 O(N)。这种方法的名称是什么?
它被称为计数排序。您以空间为代价获得速度。
我想,它没有什么特别的名字。它是一种对对象进行唯一标识的插入排序。
这是一个概述