Array -> ContainsDuplicate.swift
phpmaple opened this issue · 3 comments
phpmaple commented
simple problem:
class Solution {
func containsDuplicate(nums: [Int]) -> Bool {
return nums.count > Set(nums).count
}
}
soapyigu commented
Awesome solution, thank you
stepanhruda commented
You have to convert the entire array to a set. If you iterate one by one, you can bail out earlier once you detect the first duplicate.
soapyigu commented
Both solutions have the same complexity, I perfer phpmaple's as it is more concise.