Created
April 7, 2021 00:29
-
-
Save humpydonkey/d7483f199a0c8cc82405d4e719d0a12e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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