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

Commit8d90126

Browse files
Merge pull requestneetcode-gh#2903 from RomanGirin/main
Create 0904_fruit_into_baskets.py
2 parentsbfc3639 +261127f commit8d90126

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

‎0904_fruit_into_baskets.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
classSolution:
2+
deftotalFruit(self,fruits:List[int])->int:
3+
tr= {}
4+
l=r=0
5+
res=0
6+
whiler<len(fruits):
7+
iffruits[r]notintr:
8+
tr[fruits[r]]=1
9+
else:
10+
tr[fruits[r]]+=1
11+
whilelen(tr)>2:
12+
tr[fruits[l]]-=1
13+
iftr[fruits[l]]==0:
14+
deltr[fruits[l]]
15+
l+=1
16+
res=max(res,r-l+1)
17+
r+=1
18+
returnres

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp