We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a34ab06 commit 008f4f0Copy full SHA for 008f4f0
python/0904-fruit-into-baskets.py
@@ -0,0 +1,29 @@
1
+import collections
2
+
3
+class Solution:
4
+ def totalFruit(self, fruits: List[int]) -> int:
5
+ count = collections.defaultdict(int)
6
+ l, total, res = 0, 0, 0
7
8
+ for r in range(len(fruits)):
9
+ count[fruits[r]] += 1
10
+ total += 1
11
12
+ while len(count) > 2:
13
+ f = fruits[l]
14
+ count[f] -= 1
15
+ total -= 1
16
+ l += 1
17
+ if not count[f]:
18
+ count.pop(f)
19
20
+ res = max(res, total)
21
22
+ return res
23
24
25
26
27
28
29
0 commit comments