当前位置:网站首页>Leetcode-128 最长连续序列
Leetcode-128 最长连续序列
2022-07-01 18:33:00 【原来是大海】
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
边栏推荐
- Redis master-slave realizes 10 second check and recovery
- Batch export all pictures in PPT in one second
- Apk signature process introduction [easy to understand]
- Session layer of csframework, server and client (1)
- Search 2D matrix 2
- Computer network interview assault
- [noip2015] jumping stone
- Develop those things: add playback address authentication to easycvr platform
- Operation of cmake under win
- Check log4j problems using stain analysis
猜你喜欢
信度系数低怎么办?信度系数具体怎么算?
How to retrieve the password for opening Excel files
1380. Lucky number in matrix / 1672 Total assets of the richest customers
主成分计算权重
Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"
Samba basic usage
[PHP foundation] realize the connection between PHP and SQL database
Explain in detail the process of realizing Chinese text classification by CNN
This is the latest opportunity of the London bank trend
[image denoising] matlab code for removing salt and pepper noise based on fast and effective multistage selective convolution filter
随机推荐
MySQL connection tools
The 13th simulation problem of the single chip microcomputer provincial competition of the Blue Bridge Cup
传感器尺寸、像素、DPI分辨率、英寸、毫米的关系
Growing up in the competition -- (Guangyou's most handsome cub) Pikachu walking
From comedians to NBA Zhan Huang, check the encrypted advertisements during this super bowl
MES production equipment manufacturing execution system software
PMP daily three questions (February 15, 2022)
12种数据量纲化处理方式
How to change guns for 2D characters
golang中的select详解
How to retrieve the password for opening Excel files
t10_ Adapting to Market Participantsand Conditions
How to find the optimal learning rate
Implementation of converting PCM file to WAV
12. Design of power divider for ads usage record
Mysql database of easyclick
. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
Sum of three numbers
PCL learning materials
Flex layout