Skip to content

Instantly share code, notes, and snippets.

@humpydonkey
Created April 7, 2021 00:29
Show Gist options
  • Save humpydonkey/d7483f199a0c8cc82405d4e719d0a12e to your computer and use it in GitHub Desktop.
Save humpydonkey/d7483f199a0c8cc82405d4e719d0a12e to your computer and use it in GitHub Desktop.
class Solution:
def twoSumLessThanK(self, nums: List[int], k: int) -> int:
nums.sort()
res = -1
l, r = 0, len(nums) - 1
while l < r:
curr_sum = nums[l] + nums[r]
if curr_sum >= k:
r -= 1
else:
res = max(curr_sum, res)
l += 1
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment