Guest User

Untitled

a guest
Oct 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. class SetMismatch {
  2. func findErrorNums(_ nums: [Int]) -> [Int] {
  3. var res:[Int] = [0]
  4. var numSort = nums.sorted()
  5. for i in 0..<nums.count{
  6. if numSort[i] != i+1 {
  7. if (i+1 < nums.count && numSort[i] == numSort[i+1]) || ( i>0 && numSort[i] == numSort[i-1]){
  8. res[0] = numSort[i]
  9. }
  10. if res.count < 2 && i+1 < nums.count && numSort[i+1] != i+1{
  11. res.append(i+1)
  12. }
  13. }
  14. }
  15. if res.count == 1{
  16. res.append(nums.count)
  17. }
  18. return res.first! == 0 ? [] : res
  19. }
  20. }
Add Comment
Please, Sign In to add comment