当前位置:网站首页>Leetcode-128 longest continuous sequence
Leetcode-128 longest continuous sequence
2022-07-01 18:47:00 【It was the sea】

class Solution(object):
def longestConsecutive(self, nums):
hash_dict = dict()
max_length = 0
for num in nums:
if num not in hash_dict:
left = hash_dict.get(num - 1, 0)
right = hash_dict.get(num + 1, 0)
cur_length = 1 + left + right
if cur_length > max_length:
max_length = cur_length
hash_dict[num] = cur_length
hash_dict[num - left] = cur_length
hash_dict[num + right] = cur_length
return max_length
边栏推荐
- Principal component calculation weight
- Five degrees easy chain enterprise app is newly upgraded
- Three.js学习-相机Camera的基本操作(了解向)
- Classpath classpath
- MySQL connection tools
- 斯坦福、Salesforce|MaskViT:蒙面视觉预训练用于视频预测
- Facebook聊单,SaleSmartly有妙招!
- 研究了11种实时聊天软件,我发现都具备这些功能…
- 用WPF写一款开源方便、快捷的数据库文档查询、生成工具
- Depth first search - DFS (burst search)
猜你喜欢

Solution: you can ping others, but others can't ping me

Cloud computing - make learning easier

如何在自有APP内实现小程序实现连麦直播

12种数据量纲化处理方式

搭建一個通用監控告警平臺,架構上需要有哪些設計

Localization through custom services in the shuttle application

Lumiprobe biomolecular quantification - qudye Protein Quantification Kit

为什么独立站卖家都开始做社交媒体营销?原来客户转化率能提高这么多!

解决方案:可以ping别人,但是别人不能ping我

How to find customers for investment attraction in industrial parks
随机推荐
After studying 11 kinds of real-time chat software, I found that they all have these functions
[CF559E]Gerald and Path
Localization through custom services in the shuttle application
golang 错误处理
How to change guns for 2D characters
R语言caTools包进行数据划分、scale函数进行数据缩放、class包的knn函数构建K近邻分类器、table函数计算混淆矩阵
Implement a Prometheus exporter
Lumiprobe Lumizol RNA 提取试剂解决方案
为什么独立站卖家都开始做社交媒体营销?原来客户转化率能提高这么多!
R language uses the transmute function of dplyr package to calculate the moving window mean value of the specified data column in dataframe data, and uses ggplot2 package to visualize the line graph b
Lumiprobe bifunctional crosslinker sulfo cyanine 5 bis NHS ester
GAMES202作业0-环境搭建过程&解决遇到的问题
Rust language - cargo, crates io
Depth first search - DFS (burst search)
The R language uses the tablestack function of epidisplay package to make statistical summary tables (descriptive statistics based on the grouping of target variables, hypothesis testing, etc.). If th
[CF1476F]Lanterns
关于企业中台规划和 IT 架构微服务转型
Mysql database of easyclick
Image acquisition and playback of coaxpress high speed camera based on pxie interface
What designs are needed in the architecture to build a general monitoring and alarm platform