LeetCode Weekly Contest 38
No one has replied
heap takes O(log3) = O(1) in case of both push and pop.
Hi @dreamchase your solution is really smart~ Just one question, is there a reason for i starting at 3? I think for (int i = 1; i <= n; i++) also works
So elegent the solution is !
sort also spend time,i do not think this is a good way
@venkat Why use a priority queue which additional space, when sorting does the same job in O(n log n) while taking scalability into consideration?
So clean and easy to understand. Also very object-oriented. Amazing part is to give 2 different solutions on different situations. I strongly recommend everyone read this thread.
Disabled Categories are greyed out
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.