```
struct length
{
int count;
bool left;
bool right;
};
class Solution {
public:
int longestConsecutive(vector<int> &num) {
unordered_map<int,length> map;
length l;
l.count=1;l.left=false;l.right=false;
for(int i=0;i<num.size();i++)
{
if(map.find(num.at(i))==map.end())
map[num.at(i)]=l;
}
unordered_map<int,length>::iterator it;
for(it=map.begin();it!=map.end();it++)
{
if(it->second.left==false)
{
if(map.find(it->first-1)!=map.end() && map[it->first-1].right==false)
{
int sumlength=map[it->first].count+map[it->first-1].count;
map[it->first].count=sumlength;
map[it->first-1].count=sumlength;
it->second.left=true;
map[it->first-1].right=true;
}
}
if(it->second.right==false)
{
if(map.find(it->first+1)!=map.end() && map[it->first+1].left==false)
{
int sumlength=map[it->first].count+map[it->first+1].count;
map[it->first].count=sumlength;
map[it->first+1].count=sumlength;
it->second.right=true;
map[it->first+1].left=true;
}
}
}
it=map.begin();
int max=it->second.count;
for(it=map.begin();it!=map.end();it++)
{
if(max<it->second.count)
max=it->second.count;
}
return max;
}
};
```

I test it right on my local PC, but run wrong on OJ on this sample

Input: [1,3,5,2,4]

Output: 4

Expected: 5

So I don't know if it is correct to define a struct for this submission, my PC get 5, but on OJ, it get 4. I don't know why? Could anybody help me to explain it? thanks a lot.