Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbec4e98

Browse files
authored
Merge pull requestneetcode-gh#3189 from itsmohitnarayan/main
Created: 0350-Intersection-of-two-arrays-II.py
2 parentsac3f8e3 +a58f289 commitbec4e98

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

‎python/0079-word-search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def dfs(r, c, i):
2525
returnres
2626

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
classSolution:
2+
defintersect(self,nums1:List[int],nums2:List[int])->List[int]:
3+
counter1=Counter(nums1)
4+
counter2=Counter(nums2)
5+
6+
# Using defaultdict to handle missing keys more efficiently
7+
counter1=defaultdict(int,counter1)
8+
counter2=defaultdict(int,counter2)
9+
10+
intersection= []
11+
12+
fornum,freqincounter1.items():
13+
min_freq=min(freq,counter2[num])
14+
ifmin_freq>0:
15+
intersection.extend([num]*min_freq)
16+
17+
returnintersection

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp