Swifty Solution


  • 0
    T

    class Solution {

    func firstMissingPositive(_ nums: [Int]) -> Int {
        var sortedNums = [Int : Bool]()
    
        nums.forEach { num in
            sortedNums[num] = true
        }
    
        for num in 1 ..< Int.max  {
            if sortedNums[num] == nil {
                return num
            }
        }
    
        return 0
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.