Number of restaurants双指针
Description
Give aList
of data representing the coordinates[x,y]
of each restaurant and the customer is at the origin[0,0]
. Find then
restaurants closest to the customer firstly. Then you need to pick n restaurants which appeare firstly in theList
and the distance between the restaurant and the customer can't more than the longest distance in then
closest restaurants. Return their coordinates in the original order.
1.Coordinates in range [-1000,1000] 2.n>0 3.No same coordinates
Have you met this question in a real interview?
Yes
Problem Correction
Example
分析
其实就是找第k大,然后loop原数组顺序找出来k个比这个数小的
错了很久的是 q传入 时候被改变。顺序变了不能用q找出该有的顺序了。
Last updated