All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0101_0200.s0128_longest_consecutive_sequence.Solution.swift Maven / Gradle / Ivy

The newest version!
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Union_Find
// #Big_O_Time_O(N_log_N)_Space_O(1) #2024_06_27_Time_225_ms_(94.82%)_Space_21_MB_(31.47%)

class Solution {
    func longestConsecutive(_ nums: [Int]) -> Int {
        if nums.isEmpty {
            return 0
        }

        let sortedNums = nums.sorted()
        var maxLen = 1
        var currentLen = 1

        for i in 1..




© 2015 - 2025 Weber Informatics LLC | Privacy Policy