Skip to content

Commit ff67ed4

Browse files
add 929
1 parent 467404c commit ff67ed4

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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|
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy