I'm trying to solve leetcode problem 703, largest_element_in_a_stream in Rust.
I want to use the BinaryHeap
to solve this problem, but the BinaryHeap
in Rust is the maximum heap by default. I don't know how to transform it to a maximum heap.
I found answers in similar questions:
How do I create a BinaryHeap that pops the smallest value, not the largest?
How can I implement a min-heap of f64 with Rust's BinaryHeap?
But the answer in the two questions uses some special struct and overloads the Ord
trait, I want to solve it for primitives such as i32
.
How can I solve it?