check if there exists a[i] = 2*a[j] in an unsorted array a?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Given a unsorted sequence of a[1,...,n] of integers, give an O(nlogn) runtime algorithm to check there are two indices i and j such that a[i] =2*a[j]. The algorithm should return i=0 and j=2 on input 4,12,8,10 and false on input 4,3,1,11. I think we have to sort the array anyways which is O(nlogn). I'm not sure what to do after that. 回答1: You're right that the first step is sorting the array. Once the array is sorted, you can find out whether a given element is inside the array in O(log n) time. So if for every of the n elements, you check