1099 Two Sum Less Than K
Given an array nums
of integers and integer k
, return the maximum sum
such that there exists i < j
with nums[i] + nums[j] = sum
and sum < k
. If no i
, j
exist satisfying this equation, return -1
.
Example 1:
Example 2:
Constraints:
1 <= nums.length <= 100
1 <= nums[i] <= 1000
1 <= k <= 2000
这题一开始没认真审题,以为是L609 Two Sum V认真看了才发现,原来找的是closet,所以去看了16 3 Sum Closest。但其实更像L553 Two Sum Closest这里自己维护了一个diff,看了答案,其实可以直接用一个max来track。这个max只能在less than的时候才ok。L553那里可能是above的。T:O(nlogn), S:O(1)
Last updated