-
Notifications
You must be signed in to change notification settings - Fork 385
Closed
Labels
Description
Your LeetCode username
ya7ya1994
Category of the bug
- Question
- Solution
- Language
- Missing Test Cases
Description of the bug
This brute force solution passes because of a missing test case
[0,...<40k zeros>,1,2,3]
Code you used for Submit/Run operation
class Solution {
public int totalFruit(int[] fruits) {
int maxFruits = 0;
for (int i = 0; i < fruits.length && maxFruits < fruits.length; i++) {
maxFruits = Math.max(maxFruits,computeAll(fruits,i));
}
return maxFruits;
}
public int computeAll(int[] fruits, int beg) {
Map<Integer,Integer> basket = new HashMap();
int result = 0;
for(int i = beg; i < fruits.length; i++) {
if(!basket.containsKey(fruits[i])) {
if (basket.size() < 2) {
basket.put(fruits[i],1);
}
else {
break;
}
}
else {
basket.put(fruits[i],basket.get(fruits[i]) + 1);
}
}
for(int i : basket.values())
result += i;
return result;
}
}Language used for code
Java