> For the complete documentation index, see [llms.txt](https://851958789.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://851958789.gitbook.io/notes/0128_longest_consecutive_sequence/slt.md).

# 思路1

题目要求 O(n) 复杂度。

这是一个很有意思的算法，可以手动模拟一下

* 用哈希表存储每个端点值对应连续区间的长度
* 若数已在哈希表中：跳过不做处理
* 若是新数加入：
  * 取出其左右相邻数已有的连续区间长度 left 和 right
  * 计算当前数的区间长度为：cur\_length = left + right + 1
  * 根据 cur\_length 更新最大长度 max\_length 的值
  * 更新区间两端点的长度值
