File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed
main/java/com/fishercoder/solutions
test/java/com/fishercoder Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ Your ideas/fixes/algorithms are more than welcome!
2929
3030| # | Title | Solutions | Time | Space | Video | Difficulty | Tag
3131|-----|----------------|---------------|---------------|---------------|--------|-------------|-------------
32+ | 929| [ Unique Email Addresses] ( https://leetcode.com/problems/unique-email-addresses/ ) | [ Solution] ( ../master/src/main/java/com/fishercoder/solutions/_929.java ) | O(n) | O(n) | | Easy|
3233| 922| [ Sort Array By Parity II] ( https://leetcode.com/problems/sort-array-by-parity-ii/ ) | [ Solution] ( ../master/src/main/java/com/fishercoder/solutions/_922.java ) | O(n) | O(1) | | Easy|
3334| 917| [ Reverse Only Letters] ( https://leetcode.com/problems/reverse-only-letters/ ) | [ Solution] ( ../master/src/main/java/com/fishercoder/solutions/_917.java ) | O(n) | O(n) | | Easy|
3435| 900| [ Sort Array By Parity] ( https://leetcode.com/problems/sort-array-by-parity/ ) | [ Solution] ( ../master/src/main/java/com/fishercoder/solutions/_900.java ) | O(n) | O(1) | | Easy|
Original file line number Diff line number Diff line change 1+ package com .fishercoder .solutions ;
2+
3+ import java .util .HashMap ;
4+ import java .util .HashSet ;
5+ import java .util .Map ;
6+ import java .util .Set ;
7+
8+ public class _929 {
9+ public static class Solution1 {
10+ public int numUniqueEmails (String [] emails ) {
11+ Map <String , Set <String >> map = new HashMap <>();
12+ for (String email : emails ) {
13+ String [] parts = email .split ("@" );
14+ if (!map .containsKey (parts [1 ])) {
15+ map .put (parts [1 ], new HashSet <>());
16+ }
17+ String filteredLocalName = parts [0 ].substring (0 , parts [0 ].indexOf ('+' ));
18+ filteredLocalName = filteredLocalName .replace ("." , "" );
19+ map .get (parts [1 ]).add (filteredLocalName );
20+ }
21+ int n = 0 ;
22+ for (String key : map .keySet ()) {
23+ n += map .get (key ).size ();
24+ }
25+ return n ;
26+ }
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ package com .fishercoder ;
2+
3+ import com .fishercoder .solutions ._929 ;
4+ import org .junit .BeforeClass ;
5+ import org .junit .Test ;
6+
7+ import static org .junit .Assert .assertEquals ;
8+
9+ public class _929Test {
10+ private static _929 .Solution1 solution1 ;
11+ private static String [] emails ;
12+
13+ @ BeforeClass
14+ public static void setup () {
15+ solution1 = new _929 .Solution1 ();
16+ }
17+
18+ @ Test
19+ public void test1 () {
20+ emails = new String []{"test.email+alex@leetcode.com" , "test.e.mail+bob.cathy@leetcode.com" , "testemail+david@lee.tcode.com" };
21+ assertEquals (2 , solution1 .numUniqueEmails (emails ));
22+ }
23+
24+ }
You can’t perform that action at this time.
0 commit comments