We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent db575cf commit 071ccbbCopy full SHA for 071ccbb
Python/two-sum-less-than-k.py
@@ -0,0 +1,20 @@
1
+# Time: O(nlogn)
2
+# Space: O(1)
3
+
4
+class Solution(object):
5
+ def twoSumLessThanK(self, A, K):
6
+ """
7
+ :type A: List[int]
8
+ :type K: int
9
+ :rtype: int
10
11
+ A.sort()
12
+ result = -1
13
+ left, right = 0, len(A)-1
14
+ while left < right:
15
+ if A[left]+A[right] >= K:
16
+ right -= 1
17
+ else:
18
+ result = max(result, A[left]+A[right])
19
+ left += 1
20
+ return result
0 commit comments