Skip to content

Commit c3e1068

Browse files
authored
Update Unique Email Addresses.java
1 parent 000bad1 commit c3e1068

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

Easy/Unique Email Addresses.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
class Solution {
22
public int numUniqueEmails(String[] emails) {
3-
return Arrays.stream(emails).map(Solution::formatEmail).collect(Collectors.toSet()).size();
3+
return Arrays.stream(emails).map(Solution::getFormattedEmail).collect(Collectors.toSet()).size();
44
}
55

6-
private static String formatEmail(String email) {
7-
String localName = email.split("@")[0];
8-
return (localName.indexOf('+') != -1
9-
? localName.substring(0, localName.indexOf('+'))
10-
: localName)
11-
.replaceAll("\\.", "")
12-
+ "@"
13-
+ email.split("@")[1];
6+
private static String getFormattedEmail(String email) {
7+
String[] strs = email.split("@");
8+
int plusIdx = strs[0].indexOf('+');
9+
String formattedLocalName = strs[0].substring(0, (plusIdx == -1 ? strs[0].length() : plusIdx))
10+
.replaceAll("\\.", "");
11+
return formattedLocalName + "@" + strs[1];
1412
}
1513
}

0 commit comments

Comments
 (0)