Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def maxOperations(self, nums: List[int], k: int) -> int:
- freqMap = {}
- for x in nums:
- freqMap[x] = freqMap.get(x, 0) + 1
- pairs = 0
- for first in freqMap:
- second = k - first
- if first == second:
- pairs += freqMap.get(first, 0)//2
- else:
- pairs += min(freqMap.get(first, 0), freqMap.get(second, 0))
- freqMap[first] = 0
- return pairs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement