533.Two Sum - Closest to target
1.Description(Medium)
Given an arraynums
ofn_integers, find two integers in_nums_such that the sum is closest to a given number,_target.
Return the difference between the sum of the two integers and the target.
Example
Given arraynums
=[-1, 2, 1, -4]
, andtarget=4
.
The minimum difference is1
. (4 - (2 + 1) = 1).
Do it in O(nlogn) time complexity.
2.Code
用一个mindiff来记录最小值
Last updated