21 lines
510 B
Python
21 lines
510 B
Python
|
class Solution:
|
||
|
def maxOperations(self, nums: List[int], k: int) -> int:
|
||
|
nums.sort()
|
||
|
|
||
|
left, right = 0, len(nums) - 1
|
||
|
|
||
|
count = 0
|
||
|
while left < right:
|
||
|
total = nums[left] + nums[right]
|
||
|
|
||
|
if total == k:
|
||
|
count += 1
|
||
|
left += 1
|
||
|
right -= 1
|
||
|
elif total < k:
|
||
|
left += 1
|
||
|
else:
|
||
|
right -= 1
|
||
|
|
||
|
return count
|
||
|
|