当前位置:网站首页>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
边栏推荐
- D. Yet Another Minimization Problem
- Leetcode-128 最长连续序列
- NSI packaging script add file details
- [source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
- A wonderful time to buy and sell stocks
- Regular expression
- Popular science: what does it mean to enter the kernel state?
- Evaluation of 6 red, yellow and black list cameras: who is the safest? Who has good picture quality? From now on, let you no longer step on thunder
- Single element of an ordered array
- LeetCode 148. Sort linked list
猜你喜欢
Three.js学习-相机Camera的基本操作(了解向)
LeetCode 148. Sort linked list
Lumiprobe 生物分子定量丨QuDye 蛋白定量试剂盒
Technology implementation and Architecture Practice
Sum of three numbers
Memo - about C # generating barcode
ACM MM 2022视频理解挑战赛视频分类赛道冠军AutoX团队技术分享
Salesmartly has some tricks for Facebook chat!
NSI packaging script add file details
Halcon图片标定,使得后续图片处理过后变成与模板图片一样
随机推荐
D. Yet Another Minimization Problem
golang 错误处理
《Go题库·16》读写锁底层是怎么实现的
Mise en place d'une plate - forme générale de surveillance et d'alarme, quelles sont les conceptions nécessaires dans l'architecture?
R language uses follow up of epidisplay package Plot function visualizes the longitudinal follow-up map of multiple ID (case) monitoring indicators, and uses n.of The lines parameter specifies the num
Operating system interview assault
Cloud computing - make learning easier
Lumiprobe lumizol RNA extraction reagent solution
Leetcode-160相交链表
C language learning notes: type definition typedef and declaration external CSDN creation punch in
Reading notes series "modern methods of C language programming" -- Chapter 2
Mysql database design
Lumiprobe non fluorescent alkyne EU (5-ethynyluridine)
Write it down once Net travel management background CPU Explosion Analysis
[Chongqing Guangdong education] basic psychology reference materials of Tianjin Normal University
3、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》在本地铸造 NFT
Must see, time series analysis
Find all missing numbers in the array
The 13th simulation problem of the single chip microcomputer provincial competition of the Blue Bridge Cup
540. Single element in ordered array / 1684 Count the number of consistent strings