Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.41 KB | None | 0 0
  1. var arr = [1, 1, 8, 9, 9, 10, 10]
  2. if (arr.count < 3){
  3.     return 0// TODO: add proper exception because array does not match input requirements
  4. }
  5.  
  6. if arr[0] != arr[1]{
  7.     return arr[0]
  8. }else if (arr[arr.count-1] != arr[arr.count-2]){
  9.     return arr[arr.count-1]
  10. }else{
  11.   for i in 1...arr.count-2{
  12.       if arr[i] != arr[i+1] && arr[i] != arr[i-1]{
  13.           return arr[i]
  14.           break
  15.       }
  16.   }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement