Skip to content

为longest consecutive sequence增加了一个worst case为O(n)的解法#12

Merged
soulmachine merged 2 commits into
soulmachine:masterfrom
advancedxy:master
Jan 16, 2014
Merged

为longest consecutive sequence增加了一个worst case为O(n)的解法#12
soulmachine merged 2 commits into
soulmachine:masterfrom
advancedxy:master

Conversation

@advancedxy
Copy link
Copy Markdown
Contributor

hi,我看了一下你之前的实现,你的解法在worst case下是O(n^2)的.
比如对于[1,2,3,...,n]这样的sequence:
你要做的查询次数大致是1+2+3+...+n = O(n^2)(边角的查询忽略).
我下面提供的解法原始思路来自于http://discuss.leetcode.com/questions/1070/longest-consecutive-sequence 下的第一个回答.

soulmachine added a commit that referenced this pull request Jan 16, 2014
为longest consecutive sequence增加了一个worst case为O(n)的解法
@soulmachine soulmachine merged commit ebb384b into soulmachine:master Jan 16, 2014
@soulmachine
Copy link
Copy Markdown
Owner

Good job, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants