Finding Pairs With a Certain Sum LeetCode solution in Python
1class FindSumPairs:23def __init__(self, nums1: List[int], nums2: List[int]):4self.nums1 = sorted(nums1)5self.nums2 = nums26self.hash2 = defaultdict(int)7for n in nums2:8self.hash2[n] += 1910def add(self, index: int, val: int) -> None:11self.hash2[self.nums2[index]] -= 112self.nums2[index] += val13self.hash2[self.nums2[index]] += 11415def count(self, tot: int) -> int:16result = 017for n in self.nums1:18if n >= tot:19break20result += self.hash2[tot - n]21return result