由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 请问leetcode 上那道Longest Consecutive Sequence题
相关主题
leetcode longest consecutive sequence还是想不通!求解一道面试题 snake sequence
请教:这个10来行的leetcode程序有什么问题?leetcode的Longest Substring Without Repeating Characters解法好麻烦啊
Random Array number, Find longest consecutive sequenceLC Longest substr w/o rep char
二爷的那个Longest Consecutive Sequence的新解法?L一个电面题
Longest Consecutive Sequence 问题释疑Post 1 question: Bits operation using C programming
leetcode longest consecutive sequence怎么做find longest subarray with the equal number of 0's, 1's
问个近来看到的狗家题:longest consecutive sequence in treeleetcode 大侠,把 C++11 support 加上吧
LeetCode LongestValidParentheses大家leetcode的test case都过得去么?我的怎么经常不成?
相关话题的讨论汇总
话题: longest话题: int话题: used话题: num话题: auto
进入JobHunting版参与讨论
1 (共1页)
a***e
发帖数: 413
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;
}
k*******a
发帖数: 433
2
将auto改成int行吗?

【在 a***e 的大作中提到】
: 请问,为什么这个答案在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;

s**x
发帖数: 7506
3
auto 这个用法得用很新的compiler 吧? 确实很不错的 feature, 老的 compiler
may not support this. c++11?
change to:
for (size_t i =0; i< num.size(); i++) {
}
variable name num is not good. use numList or something like that.
1 (共1页)
进入JobHunting版参与讨论
相关主题
大家leetcode的test case都过得去么?我的怎么经常不成?Longest Consecutive Sequence 问题释疑
Leetcode上Two sum只能过3个case, VS能过,大牛进来看看是怎么回事leetcode longest consecutive sequence怎么做
请问longest common consecutive sequence用什么算法?问个近来看到的狗家题:longest consecutive sequence in tree
问一个C++的小细节,和leetcode也有关LeetCode LongestValidParentheses
leetcode longest consecutive sequence还是想不通!求解一道面试题 snake sequence
请教:这个10来行的leetcode程序有什么问题?leetcode的Longest Substring Without Repeating Characters解法好麻烦啊
Random Array number, Find longest consecutive sequenceLC Longest substr w/o rep char
二爷的那个Longest Consecutive Sequence的新解法?L一个电面题
相关话题的讨论汇总
话题: longest话题: int话题: used话题: num话题: auto