How to let quick select cope large duplicate values?


  • 0
    R

    When I use Quick Select function elsewhere (LeetCode 324), a case reports a stack overflow error.

    The reason is at the case where size=30k+, and all the numbers are 1,2 and 3 (lot of duplicates).

    The quick select starts to be degenerated and call (begin+1, end, k-1) because almost all the items existing in range equals the target...

    Anyone have ways of remedy? How to optimize quick select to cope this situation?


Log in to reply
 

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