Rust | Simple & Fast | HashSet | O(n)
\nuse std::collections::HashSet;\n\nimpl Solution {\n    pub fn longest_consecutive(nums: Vec<i32>) -> i32 {\n        let num_set: HashSet<_> = nums.into_iter()
```\nuse std::collections::HashSet;\n\nimpl Solution {\n    pub fn longest_consecutive(nums: Vec<i32>) -> i32 {\n        let num_set: HashSet<_> = nums.into_iter().collect();\n        let mut ans = 0;\n        for &num in &num_set {\n            if !num_set.contains(&(num - 1)) {\n                let count = (num..).take_while(|x| num_set.contains(x)).count();\n                ans = ans.max(count);\n            }\n        }\n        ans as i32\n    }\n}\n```
['Rust']