Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. func missingNumber(_ nums: [Int]) -> Int {
  2. let count = nums.count
  3. // What's this all about?
  4. var sum = ((0 + count)*(count + 1)) / 2
  5. for i in 0..<count {
  6. sum -= nums[i]
  7. }
  8. return sum
  9. }
  10.  
  11. let array = [0, 1, 3] // missing # is 2
  12. missingNumber(array) // returns 2...HOW?!?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement