The test case is [1,1,2,2,2,1].In the run the result is 3 but in submit the result is 6.Anyone could help me?

Here is my code

```
class Solution {
public:
int findShortestSubArray(vector<int>& nums) {
if(nums.size()<2) return nums.size();
int count[50000];
map<int,int> num2index;
int maxcount = 0,mindis = 0;
for(int i =0;i<nums.size();++i){
if(num2index.count(nums[i]) == 0){
num2index[nums[i]] = i;
count[nums[i]]++;
}else{
count[nums[i]]++;
}
if(count[nums[i]]>maxcount){
maxcount = count[nums[i]];
mindis = i - num2index[nums[i]]+1;
}else if(count[nums[i]]==maxcount){
int dis = i - num2index[nums[i]]+1;
if(dis<mindis){
maxcount = count[nums[i]];
mindis = dis;
}
}
}
return mindis;
}
};
```