Skip to content

Commit

Permalink
Merge pull request soapyigu#282 from peacemoon/shorten_findmissingpos…
Browse files Browse the repository at this point in the history
…sitive

Shorten FindMissingPossitive.
  • Loading branch information
soapyigu authored Dec 9, 2019
2 parents 2c6bb3c + efb046d commit e4f426c
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Array/FirstMissingPositive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

class FirstMissingPositive {
func firstMissingPositive(_ nums: [Int]) -> Int {
var set = Set<Int>()

nums.forEach { set.insert($0) }
let set = Set(nums)

for i in 0..<nums.count {
if !set.contains(i + 1) {
Expand All @@ -19,4 +17,4 @@ class FirstMissingPositive {

return nums.count + 1
}
}
}

0 comments on commit e4f426c

Please sign in to comment.