一批愤怒分子即将到来。 问题在于找到“first pair of number from the stream that increase to a specific Value (say, k).
在静态阵列下,可以采用以下两种办法:
- Approach (1): Sort the array, use two pointers to beginning and end of array and compare.
- Approach (2): Use hashing, i.e. if A[i]+A[j]=k, then A[j]=k-A[i]. Search for A[j] in the hash table.
但是,这两种办法都没有很好地扩大上游。 任何关于有效解决这一问题的想法?