|
Good Answer:Sort the array.Then,keep track of two pointers in the array,one atthe beginning and one at the end.Whenever the sum of the current two integers isless than x,move the first pointer forwards,and whenever the sum is greater than x,move these condpointer backwards.If you cannot find two numbers that add to xbefore one of the pointers meet,then there is no pair of integers that sum to x. |
|
共 1 个关于本帖的回复 最后回复于 2013-7-30 17:14