Medium
,Array
,Hash Table
,Sliding Window
You are visiting a farm that has a single row of fruit trees arranged from left to right. The trees are represented by an integer array fruits
where fruits[i]
is the type of fruit the ith tree produces.
You want to collect as much fruit as possible. However, the owner has some strict rules that you must follow:
Given the integer array fruits
, return the maximum number of fruits you can pick.
Example 1:
Example 2:
Example 3:
Constraints:
fruits.length
<= 105fruits[i]
< fruits.length
Yen-Chi ChenTue, Feb 7, 2023
Time:
Extra Space:
XD Feb 7, 2023
Yen-Chi ChenTue, Feb 7, 2023
參考前面兩位大神的解法寫出來了,感恩兩位大神!
MarsgoatFeb 9, 2023