Any solution using BST?


  • 0
    W

    since the tag is binary search tree, but I can only find out the solution with slide window.


  • 2
    M

    BST tree actually contains the k+1 elements and you can quickly find the two closest numbers by O(lgn) insert and search operation.


  • 0
    P

    I notice some good solutions here, usages including TreeSet in Java, multiset in C++, all have something to do with BST :p


Log in to reply
 

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