1 & 167. Two Sum I & II ( Input array is sorted )

There is an array with integers, if there is sum of two numbers equals target, return true; if there is not, return false.

 

Solution:

 

Input array is sorted:

O(NlogN)

Use binary search or two pointers.

 

Unsorted:

O(N)

Use hash map, key = target - a[i], value = a[i]

Search and find containsKey

posted @ 2017-01-10 11:02  CornerCase  阅读(97)  评论(0编辑  收藏  举报