Longest Consecutive Sequence(未)
2015-08-02 15:33
399 查看
题目128:Longest Consecutive Sequence
题目描述:Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
For example,
Given [100, 4, 200, 1, 3, 2],
The longest consecutive elements sequence is [1, 2, 3, 4]. Return its length: 4.
Your algorithm should run in O(n) complexity.
题目分析:
在一个没有排序的整型数组中,找到长度最长的顺序连续的子序列,举例的很清楚,要求时间复杂度是O(n) 。
思路分析:
如果时间复杂度没有要求,则先对数组排序,排序后遍历,但排序的时间复杂度是O(nlog n),不符合要求;
有看过别人的解法,有用C++ STL中的set,set和multiset都会自动对元素排序,排序复杂度就会上去。
先写到这里,回来来补充。
相关文章推荐
- Sys.WebForms.PageRequestManagerServerErrorException: 在服务器上处理请求时出现未知错误解决办法
- Activity生命周期交互设计思想和应用场景(附源码)
- poj 1679 The Unique MST 判断最小生成树是否唯一(图论)
- apue 第十五章 进程间通信
- UILabel字体加粗 IOS
- leetcode 60: Permutation Sequence
- Common Subsequence(最长公共子序列DP)
- 调整UILabel行高间距
- codeforces 566F F. Clique in the Divisibility Graph(dp)
- 常用类库StringBuilder
- 【LeetCode】232 & 225 - Implement Queue using Stacks & Implement Stack using Queues
- 在iOS 8中使用UIAlertController
- 【转】UITableView使用详解
- 洛谷1373 小a和uim之大逃离
- easyui dataGrid接收嵌套JSON
- easyui dialog子窗口关闭父窗口
- android:layout_centerHorizontal="true"和 android:gravity="center_horizontal"什么区别?
- Selenium2学习-026-WebUI自动化实战实例-024-获取页面元素
- uuid (guid)全局唯一标识符
- Android SDK Tools Platform-tools Build-tools