当前位置:网站首页>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
边栏推荐
- LeetCode 148. Sort linked list
- 证券开户安全么,有没有什么样的危险呢
- Draw drawing process of UI drawing process
- How to learn automated testing?
- 12. Design of power divider for ads usage record
- Penetration practice vulnhub range Keyring
- Financial judgment questions
- PMP daily three questions (February 15, 2022)
- Data query language (DQL)
- [today in history] February 15: Pascal's father was born; YouTube was founded; Kotlin language comes out
猜你喜欢
Bernoulli distribution (a discrete distribution)
Setting up a time server requires the client to automatically synchronize the time of the server at 9 a.m. every day
What impact will multinational encryption regulation bring to the market in 2022
主成分计算权重
Quick foundation of group theory (5): generators, Kelley graphs, orbits, cyclic graphs, and "dimensions" of groups?
1380. Lucky number in matrix / 1672 Total assets of the richest customers
[PHP foundation] realize the connection between PHP and SQL database
A database editing gadget that can edit SQLite database. SQLite database replaces fields. SQL replaces all values of a field in the database
A wonderful time to buy and sell stocks
Set the style of QT property sheet control
随机推荐
Redis主从实现10秒检查与恢复
信度系数低怎么办?信度系数具体怎么算?
Debiasing word embeddings | talking about word embedding and deviation removal # yyds dry goods inventory #
Relational database management system of easyclick
Samba basic usage
[CF1476F]Lanterns
Software construction scheme of smart factory collaborative management and control application system
[today in history] February 15: Pascal's father was born; YouTube was founded; Kotlin language comes out
Cloud computing - make learning easier
To improve the efficiency of office collaboration, trackup may be the best choice
Record 3 - the state machine realizes key control and measures the number of external pulses
What are the legal risks of NFT brought by stars such as curry and O'Neill?
Growing up in the competition -- (Guangyou's most handsome cub) Pikachu walking
[PHP foundation] realize the connection between PHP and SQL database
540. Single element in ordered array
Talk about the favorite tools used by project managers
On the language internationalization of Yongzhong Office
Subnet division and summary
Yuancosmos game farmersworld farmers world - core content of the second conference in China!
因子分析怎么计算权重?