且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在数组中发现的最大尺寸为k的每个窗口

更新时间:2023-02-10 11:29:46

您需要一个快速的数据结构,它可以添加,删除和查询的最大元素小于O(n)时间(你可以用一个数组,如果为O(n)或O(nlogn)是可以接受的)。您可以使用一个堆,平衡二叉搜索树,跳跃列表,或任何其他排序的数据结构,在O的执行这些操作(的log(n))。

You need a fast data structure that can add, remove and query for the max element in less than O(n) time (you can just use an array if O(n) or O(nlogn) is acceptable). You can use a heap, a balanced binary search tree, a skip list, or any other sorted data structure that performs these operations in O(log(n)).

好消息是,最流行的语言都实现了一个排序的数据结构支持这些操作为您服务。 C ++有的std ::设为的std :: multiset的(你可能需要后者)和Java具有 TreeSet的

The good news is that most popular languages have a sorted data structure implemented that supports these operations for you. C++ has std::set and std::multiset (you probably need the latter) and Java has TreeSet.