Why is max-heap used in other solutions?


  • 0
    W

    Could anyone please help to clarify why max-heap is used for this problem? It seems to look for k smallest difference between node value and target value. Thus, min-heap need to be used, i.e., sorting the difference from smallest to largest. Then, why the max-heap is used to take the k largest difference, then? Thanks for your help!


Log in to reply
 

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