#include <vector>
using namespace std;
class Solution { // review O(N) O(1)
public:
int totalFruit(vector<int>& f){
int a = -1, b = -1, run = 0, cur = 0, ans = 0;
for (int x : f) {
cur = (x == a || x == b) ? cur + 1 : run + 1;
run = (x == b) ? run + 1 : 1;
if (x != b) { a = b; b = x; }
ans = (ans > cur) ? ans : cur;
}
return ans;
}
};