当前位置:网站首页>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
边栏推荐
- JS how to convert a string with a delimiter into an n-dimensional array
- Review Net 20th anniversary development and 51aspx growth
- Relational database management system of easyclick
- At present, where is the most formal and safe account opening for futures speculation? How to open a futures account?
- Blue Bridge Cup real problem: word analysis
- 必看,时间序列分析
- 目前炒期货在哪里开户最正规安全?怎么期货开户?
- 540. Single element in ordered array / 1684 Count the number of consistent strings
- Oracle TRUNC function processing date format
- 传感器尺寸、像素、DPI分辨率、英寸、毫米的关系
猜你喜欢
![[PHP foundation] realize the connection between PHP and SQL database](/img/eb/c8953eddfe3b19b0adb5529957d275.jpg)
[PHP foundation] realize the connection between PHP and SQL database

How to find the optimal learning rate

Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash

Mysql database design

因子分析怎么计算权重?

Depth first search - DFS (burst search)

Review Net 20th anniversary development and 51aspx growth

Check log4j problems using stain analysis

Happy new year | 202112 monthly summary

Leetcode 1380. Lucky numbers in the matrix (save the minimum number of each row and the maximum number of each column)
随机推荐
Single element of an ordered array
Bug of QQ browser article comment: the commentator is wrong
Growing up in the competition -- (Guangyou's most handsome cub) Pikachu walking
Relationship between sensor size, pixel, dpi resolution, inch and millimeter
2022 Heilongjiang latest fire protection facility operator simulation test question bank and answers
Is the fund of futures account safe? How to open an account?
D. Yet Another Minimization Problem
C# SelfHost WebAPI (2)
From comedians to NBA Zhan Huang, check the encrypted advertisements during this super bowl
Bernoulli distribution (a discrete distribution)
February 16, 2022 Daily: graph neural network self training method under distribution and migration
Small exercise -- subnet division and summary
12. Design of power divider for ads usage record
Classpath classpath
Apache iceberg source code analysis: schema evolution
Draw drawing process of UI drawing process
Explain in detail the process of realizing Chinese text classification by CNN
What are the six steps of the software development process? How to draw software development flow chart?
A wonderful time to buy and sell stocks
SCP -i private key usage