Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/0079-word-search.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def dfs(r, c, i):
return res

# To prevent TLE,reverse the word if frequency of the first letter is more than the last letter's
count = defaultdict(int, sum(map(Counter, board), Counter()))
count = sum(map(Counter, board), Counter())
if count[word[0]] > count[word[-1]]:
word = word[::-1]

Expand Down
17 changes: 17 additions & 0 deletions python/0350-intersection-of-two-arrays-ii.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution:
def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
counter1 = Counter(nums1)
counter2 = Counter(nums2)

# Using defaultdict to handle missing keys more efficiently
counter1 = defaultdict(int, counter1)
counter2 = defaultdict(int, counter2)

intersection = []

for num, freq in counter1.items():
min_freq = min(freq, counter2[num])
if min_freq > 0:
intersection.extend([num] * min_freq)

return intersection