1099. Two Sum Less Than K

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 1099

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