Problem: https://leetcode.com/explore/interview/card/google/67/sql-2/3044/
| 3 | */ |
| 4 | |
| 5 | class Solution { |
| 6 | public int numUniqueEmails(String[] emails) { |
| 7 | Set<String> uniqueEmails = new HashSet<String>(); |
| 8 | |
| 9 | for (String email: emails) { |
| 10 | String[] emailParts = email.split("@"); |
| 11 | String localName = emailParts[0]; |
| 12 | String domainName = emailParts[1]; |
| 13 | |
| 14 | if (localName.contains("+")){ |
| 15 | String localNameWithPlusSign = localName; |
| 16 | localName = localNameWithPlusSign.split("\\+")[0]; |
| 17 | } |
| 18 | |
| 19 | if (localName.contains(".")){ |
| 20 | String localNameWithPeriod = localName; |
| 21 | localName = localNameWithPeriod.replace(".",""); |
| 22 | } |
| 23 | |
| 24 | String formattedEmail = localName + "@" + domainName; |
| 25 | uniqueEmails.add(formattedEmail); |
| 26 | } |
| 27 | |
| 28 | return uniqueEmails.size(); |
| 29 | } |
| 30 | } |
nothing calls this directly
no outgoing calls
no test coverage detected