微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

array_unique PHP的操作数

有人知道array_unique()的Big O吗?

我还没有遍历源代码,但是我可以想象它遍历每个值并检查是否在数组中,它是否为O(n ^ 2),对吗?

谢谢

解决方法:

因为它使用排序而不是O(n ^ 2)扫描,所以它是O(nlogn).

Note that keys are preserved. array_unique() sorts the values treated as string at first, then will keep the first key encountered for every value, and ignore all following keys. It does not mean that the key of the first related value from the unsorted array will be kept.

引用自http://php.net/manual/en/function.array-unique.php

编辑:记住要对Google进行检查,查看手册,检查是否存在问题,然后再提出要求.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐