File tree 1 file changed +7
-9
lines changed
1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change 1
1
class Solution {
2
2
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 ();
4
4
}
5
5
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 ];
14
12
}
15
13
}
You can’t perform that action at this time.
0 commit comments