forked from AnasImloul/Leetcode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnique Email Addresses.java
30 lines (29 loc) · 1006 Bytes
/
Unique Email Addresses.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Runtime: 27 ms (Top 57.45%) | Memory: 46.9 MB (Top 71.39%)
class Solution {
public int numUniqueEmails(String[] emails) {
Set<String> finalEmails = new HashSet<>();
for(String email: emails){
StringBuilder name = new StringBuilder();
boolean ignore = false;
for(int i=0;i<email.length();i++){
char c = email.charAt(i);
switch(c){
case '.':
break;
case '+':
ignore = true;
break;
case '@':
name.append(email.substring(i));
i = email.length();
break;
default:
if(!ignore) name.append(c);
}
}
finalEmails.add(name.toString());
}
finalEmails.forEach(System.out::println);
return finalEmails.size();
}
}