Skip to content

Commit dba126d

Browse files
committed
Jul 06
1 parent 33457da commit dba126d

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from collections import Counter
2+
3+
4+
class FindSumPairs:
5+
6+
def __init__(self, nums1: list[int], nums2: list[int]):
7+
self.nums1 = nums1
8+
self.nums2 = nums2
9+
self.counts2 = Counter(nums2)
10+
11+
def add(self, index: int, val: int) -> None:
12+
self.counts2[self.nums2[index]] -= 1
13+
self.nums2[index] += val
14+
self.counts2[self.nums2[index]] += 1
15+
16+
def count(self, tot: int) -> int:
17+
result = 0
18+
for n1 in self.nums1:
19+
result += self.counts2[tot - n1]
20+
return result
21+
22+
23+
def main():
24+
obj = FindSumPairs([1, 1, 2, 2, 2, 3], [1, 4, 5, 2, 5, 4])
25+
assert obj.count(7) == 8
26+
obj.add(3, 2)
27+
assert obj.count(8) == 2
28+
assert obj.count(4) == 1
29+
obj.add(0, 1)
30+
obj.add(1, 1)
31+
assert obj.count(7) == 11
32+
33+
34+
if __name__ == '__main__':
35+
main()

2025-07-July-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| July 03 | [3304. Find the K-th Character in String Game I](https://leetcode.com/problems/find-the-k-th-character-in-string-game-i/) | Easy | Solved |
1010
| July 04 | [3307. Find the K-th Character in String Game II](https://leetcode.com/problems/find-the-k-th-character-in-string-game-ii/) | Hard | Unsolved |
1111
| July 05 | [1394. Find Lucky Integer in an Array](https://leetcode.com/problems/find-lucky-integer-in-an-array/) | Easy | Solved |
12-
| July 06 | []() | | |
12+
| July 06 | [1865. Finding Pairs With a Certain Sum](https://leetcode.com/problems/finding-pairs-with-a-certain-sum/) | Medium | Solved |
1313
| July 07 | []() | | |
1414
| July 08 | []() | | |
1515
| July 09 | []() | | |
@@ -41,5 +41,5 @@
4141
| Level | Problems | Solved | Unsolved |
4242
| --- | --- | --- | --- |
4343
| Easy | 3 | 3 | 0 |
44-
| Medium | 0 | 0 | 0 |
44+
| Medium | 1 | 1 | 0 |
4545
| Hard | 2 | 0 | 2 |

0 commit comments

Comments
 (0)