C++ solution, I think my code work at O(n), who can improve ?


  • 0
    E

    I think my code work O(n)
    Idea it's use priority_queue(PQ), because in PQ erase and add element work at O(1); Then I will add all vectors element in PQ and PQ do a automatically sort. And last action need to check to Longest Consecutive Sequence. First time I want to sorted to increase, but it get a bad time 36ms. I think it's bad idea). If I'm wrong, say about it pleas <3 and improve what ? and why ? am I wrong. Thank you to attention.
    code here


  • 0
    P

    no, it's not O(n). every time you push to prioriry queue - it's O(logN). and you're doing this in the cycle, so you have more than O(n)


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.