大家常推荐的us mattress上的床垫link是哪个啊# Living
a*e
1 楼
请问,为什么这个答案在oj能通过,但在VS2010中编译for (auto i:num)老是出错呢?
多谢
error C3531: 'i': a symbol whose type contains 'auto' must have an
initializer
int longestConsecutive(vector &num) {
unordered_map used;
for (auto i:num) used[i]=false;
int longest = 0;
for (auto i:num)
{
if (used[i])
continue;
int length = 1;
used[i] = true;
for (int j=i+1; used.find(j)!=used.end(); j++)
{
used[j]=true;
length++;
}
for (int j=i-1; used.find(j)!=used.end(); j--)
{
used[j]=true;
length++;
}
longest = max(longest,length);
}
return longest;
}
多谢
error C3531: 'i': a symbol whose type contains 'auto' must have an
initializer
int longestConsecutive(vector
unordered_map
for (auto i:num) used[i]=false;
int longest = 0;
for (auto i:num)
{
if (used[i])
continue;
int length = 1;
used[i] = true;
for (int j=i+1; used.find(j)!=used.end(); j++)
{
used[j]=true;
length++;
}
for (int j=i-1; used.find(j)!=used.end(); j--)
{
used[j]=true;
length++;
}
longest = max(longest,length);
}
return longest;
}