title: Swift how does my function exceed O(n)?
body: <p>I am trying to work on a leetcode problem that asks for</p>
  <blockquote>
  <p>Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.</p>
  <p>Find all the elements of [1, n] inclusive that do not appear in this array.</p>
  </blockquote>
  <p>My solution to the problem is:</p>
  <pre><code>func findDisappearedNumbers(_ nums: [Int]) -&gt; [Int] {
      var returnedArray = [Int]()
  
      if nums.isEmpty == false {
          for i in 1...nums.count {
              if nums.contains(i) == false {
                  returnedArray.append(i)
              }
          }
      } else {
          returnedArray = nums
      }
      return returnedArray
  }
  </code></pre>
  <p>However, leetcode tells me that my solution is &quot;Time limit exceeded&quot;</p>
  <p>Shouldn't my solution be O(n)? I am not sure where did I made it to be greater than O(n).</p>