Leetcode128.『最长连续序列』学习笔记 发布时间:2026/9/25 0:46:53 尧图网站设计 1. 使用set的简洁解法classSolution:deflongestConsecutive(self,nums:List[int])-int:numsset(nums)longest0fornuminnums:ifnum-1notinnums:currnumwhilenuminnums:num1longestmax(longest,num-curr)returnlongest加了set之后if num - 1 not in nums就变成了“哈希查找” 网站设计 设计经验 学习干货 返回列表