Advertisement
HXXXXJ

929. Unique Email Addresses

Apr 13th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.75 KB | None | 0 0
  1.     func numUniqueEmails(_ emails: [String]) -> Int {
  2.         var nSet = Set<String>()
  3.         for e in emails{
  4.             nSet.insert(parseEmail(e))
  5.         }
  6.         return nSet.count
  7.     }
  8.    
  9.     func parseEmail(_ str: String) -> String{
  10.         // var i = 0
  11.         let arr = Array(str)
  12.         var res = ""
  13.         var foundP = false
  14.         for i in 0 ..< arr.count {
  15.             if arr[i] == "@"{
  16.                 res.append(String(arr[i ..< arr.count ]))
  17.                 return res
  18.             }
  19.             if foundP { continue }
  20.             if arr[i] == "+" {
  21.                 foundP = true
  22.                 continue
  23.             }
  24.             if arr[i] == "." {continue}
  25.             res.append(arr[i])
  26.         }
  27.         return res
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement