利口 酒气散 和 陆武吧 的结合:
Given an integer array, two integers k andx, find the k closest elements to x in the array.
base solution:priorityqueue,时间复杂度O(nlogn)
follow up 1: 如何降低时间复杂度?
follow up 2:如果inputarray里的元素是升序排列的,如何进一步降低时间复杂度?
利口 酒气散 和 陆武吧 的结合:
Given an integer array, two integers k andx, find the k closest elements to x in the array.
base solution:priorityqueue,时间复杂度O(nlogn)
follow up 1: 如何降低时间复杂度?
follow up 2:如果inputarray里的元素是升序排列的,如何进一步降低时间复杂度?