z*y 发帖数: 1311 | 1 Given an array of numbers and a number X
find two elements a, b from the array such that a+b = X
My solution is sorting first then binary search
O(n log n)
I don't think it can be improved further, right? | l*********8 发帖数: 4642 | | g*********e 发帖数: 14401 | 3 if you have more memory, you can use a hashtable to store all the values and
check each's complimentary value in O(n) | p*****2 发帖数: 21240 | 4 这不是经典题吗?sort之后two pointer,比binary search 复杂度低。 |
|