272. Closest Binary Search Tree Value II

idea : inorder traversal get sorted list+ leetcode 658 (binary search + sliding window)

time: O(n + logn + k) = O(n)

space: O(n)

Follow up: Assume that the BST is balanced. Could you solve it in less than O(n) runtime (where n = total nodes)? ...oh, give up first.

Last updated

Was this helpful?