当前位置:网站首页>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
边栏推荐
- Data query language (DQL)
- Flex layout
- February 16, 2022 Daily: graph neural network self training method under distribution and migration
- At present, where is the most formal and safe account opening for futures speculation? How to open a futures account?
- Is online stock account opening safe? Is it reliable?
- Penetration practice vulnhub range Tornado
- Is the fund of futures account safe? How to open an account?
- The ultimate version of the 13th simulation of the single chip microcomputer provincial competition of the Blue Bridge Cup
- Sanfeng cloud 0215 I often use
- Financial judgment questions
猜你喜欢

How to retrieve the password for opening Excel files

信度系数低怎么办?信度系数具体怎么算?

Explain in detail the process of realizing Chinese text classification by CNN

Samba basic usage

Data query language (DQL)

Quick foundation of group theory (5): generators, Kelley graphs, orbits, cyclic graphs, and "dimensions" of groups?

Distributed task queue: Celery usage record

Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"

Mysql database design

Operation of cmake under win
随机推荐
Explain in detail the process of realizing Chinese text classification by CNN
Detailed explanation of select in golang
Detailed explanation of ArrayList expansion
Xia CaoJun ffmpeg 4.3 audio and video foundation to engineering application
Happy new year | 202112 monthly summary
Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
Domestic spot silver should be understood
网上股票开户安全吗?是否可靠?
Pytorch crossentropyloss learning
[2. Basics of Delphi grammar] 4 Object Pascal operators and expressions
SPIE Western optoelectronics exhibition returned offline and successfully held a science and engineering event
Operating system interview assault
Fresh, 2022 advanced Android interview must know 100 questions (interview questions + answer analysis)
Convert the robot's URDF file to mujoco model
D @ safety and dip1000
Penetration practice vulnhub range Nemesis
PTA year of birth
Setting up a time server requires the client to automatically synchronize the time of the server at 9 a.m. every day
Apk signature process introduction [easy to understand]
C# SelfHost WebAPI (2)