LintCode:最长连续序列
来源:互联网 发布:清华大学王斌算法考试 编辑:程序博客网 时间:2024/05/01 21:30
LintCode:最长连续序列
题目要求O(n)复杂度,我这个算法虽然通过了,但是排序操作至少就是O(nlgn)的复杂度了,额,还得再想想。
class Solution: """ @param num, a list of integer @return an integer """ def longestConsecutive(self, num): # write your code here if not num: return num = sorted(list(set(num))) ans = 1 tmp = 1 for i in range(1, len(num)): if num[i] - num[i-1] == 1 or num[i] - num[i-1] == 0: tmp += 1 else: tmp = 1 ans = max(ans, tmp) return ans
0 0
- lintcode ----最长连续序列
- LintCode:最长连续序列
- LintCode-最长连续序列
- LintCode : 最长连续序列
- LintCode-最长连续序列
- lintcode--最长连续序列
- 最长连续序列-LintCode
- lintcode-最长连续子序列
- LintCode--最长上升连续子序列
- lintcode-最长上升连续子序列-397
- 最长上升连续子序列(LintCode)
- LintCode- 最长上升连续子序列
- lintCode刷题--最长上升连续子序列
- LintCode:最长上升连续子序列
- *[Lintcode]Longest Consecutive Sequence最长连续序列
- lintcode -- 最长上升连续子序列
- lintcode:最长上升连续子序列
- LintCode: 最长上升连续子序列
- Leetcode解题报告:215. Kth Largest Element in an Array
- java项目从win上布署到linux上报java.lang.ArrayIndexOutOfBoundsException错误
- Linux_Ubuntu_openWrt源码目录结构
- Linux 命令:wget
- mysql数据库设计小技巧
- LintCode:最长连续序列
- C#读取网卡地址的几种方法
- Java线程总结(十三):并发包------线程返回结果Callable和 Future
- mysql自定义排序规则函数——field()
- OpenCV开发环境搭建:VS2015+OpenCV3.1.0
- Linux_Ubuntu_openWrt编译环境学习_编译出错
- C#获取本地计算机信息
- java回调机制
- java8 Lambda表达式的学习与测试