Gyh's Braindump

904. Fruit Into Baskets

tags
sliding window,subarray
source
904

Solution

Solution 1

use haspmap, key is fruit type, value is this type’s last index iterate whole array

Complexity

  • time: O(n)
  • space: O(n)

Solution 2

https://leetcode.com/problems/fruit-into-baskets/discuss/170745/Problem%3A-Longest-Subarray-With-2-Elements