Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func numUniqueEmails(_ emails: [String]) -> Int {
- var nSet = Set<String>()
- for e in emails{
- nSet.insert(parseEmail(e))
- }
- return nSet.count
- }
- func parseEmail(_ str: String) -> String{
- // var i = 0
- let arr = Array(str)
- var res = ""
- var foundP = false
- for i in 0 ..< arr.count {
- if arr[i] == "@"{
- res.append(String(arr[i ..< arr.count ]))
- return res
- }
- if foundP { continue }
- if arr[i] == "+" {
- foundP = true
- continue
- }
- if arr[i] == "." {continue}
- res.append(arr[i])
- }
- return res
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement