列表排名算法
给定一个可以按任何顺序排列的数字列表,例如
3, -5, -1, 2, 7, 12, -8
我想生成一个代表其排名的列表,在本例中为
4, 1, 2, 3, 5, 6, 0
数字实际上是类的有序列表的某些成员。 请注意,列表的顺序不会改变,只是根据排名进行计数。
(这些数字代表 z 顺序,但可能还有其他用途)
Given a list of numbers, which can be in any order, such as
3, -5, -1, 2, 7, 12, -8
I would like to produce a list which represents their rank, which in this case would be
4, 1, 2, 3, 5, 6, 0
The numbers are actually some member of an ordered list of classes. Note that the order of the list does not change, they just get counted according to their rank.
(these numbers represent a z-order, but there could be other uses)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我的解决方案,尚未测试:
它是 O(n^2),如您所见......:(
This is my solution, untested as of yet:
It is O(n^2), as you can see.... :(