1099. Two Sum Less Than K
On This Page
class Solution:
def twoSumLessThanK(self, nums: List[int], k: int) -> int:
nums.sort()
i, j = 0, len(nums) - 1
res = -1
while i < j:
if (s := nums[i] + nums[j]) < k:
res = max(res, s)
i += 1
else:
j -= 1
return res