File tree 2 files changed +30
-3
lines changed
2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change 1
1
# LeetCode Algorithms
2
2
3
- ![ problems-solved] ( https://img.shields.io/badge/Problems%20Solved-206 /2081-1f425f.svg )
4
- ![ problems-solved-java] ( https://img.shields.io/badge/Java-206 /2081-1abc9c.svg )
3
+ ![ problems-solved] ( https://img.shields.io/badge/Problems%20Solved-215 /2081-1f425f.svg )
4
+ ![ problems-solved-java] ( https://img.shields.io/badge/Java-215 /2081-1abc9c.svg )
5
5
![ problems-solved-python] ( https://img.shields.io/badge/Python-186/2081-1abc9c.svg )
6
6
[ ![ PRs Welcome] ( https://img.shields.io/badge/PRs-welcome-brightgreen.svg )] ( CONTRIBUTING.md )
7
7
[ ![ cp] ( https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg )] ( https://github.com/anishLearnsToCode/competitive-programming )
250
250
| 917 | [ Reverse Only Letters] ( https://leetcode.com/problems/reverse-only-letters ) | [ ![ Java] ( assets/java.png )] ( src/ReverseOnlyLetters.java ) |
251
251
| 922 | [ Sort Array by Parity II] ( https://leetcode.com/problems/sort-array-by-parity-ii ) | [ ![ Java] ( assets/java.png )] ( src/SortArrayByParityII.java ) |
252
252
| 925 | [ Long Pressed Name] ( https://leetcode.com/problems/long-pressed-name ) | [ ![ Java] ( assets/java.png )] ( src/LongPressedName.java ) |
253
- | 929 | [ Unique Email Addresses] ( https://leetcode.com/problems/unique-email-addresses ) | |
253
+ | 929 | [ Unique Email Addresses] ( https://leetcode.com/problems/unique-email-addresses ) | [ ![ Java ] ( assets/java.png )] ( src/UniqueEmailAddresses.java ) |
254
254
| 933 | [ Number of Recent Calls] ( https://leetcode.com/problems/number-of-recent-calls ) | |
255
255
| 937 | [ Reorder Data In Log Files] ( https://leetcode.com/problems/reorder-data-in-log-files ) | |
256
256
| 938 | [ Range Sum of BST] ( https://leetcode.com/problems/range-sum-of-bst ) | |
Original file line number Diff line number Diff line change
1
+ import java .util .HashSet ;
2
+ import java .util .Set ;
3
+
4
+ public class UniqueEmailAddresses {
5
+ public int numUniqueEmails (String [] emails ) {
6
+ Set <String > uniqueEmails = new HashSet <>();
7
+ for (String emailAddress : emails ) {
8
+ uniqueEmails .add (getActualEmailAddress (emailAddress ));
9
+ }
10
+ return uniqueEmails .size ();
11
+ }
12
+
13
+ private static String getActualEmailAddress (String email ) {
14
+ StringBuilder result = new StringBuilder ();
15
+ for (int index = 0 ; index < email .length () ; index ++) {
16
+ if (email .charAt (index ) == '+' ) {
17
+ while (email .charAt (index ) != '@' ) index ++;
18
+ result .append (email .substring (index ));
19
+ break ;
20
+ } else if (email .charAt (index ) == '@' ) {
21
+ result .append (email .substring (index ));
22
+ break ;
23
+ } else if (email .charAt (index ) != '.' ) result .append (email .charAt (index ));
24
+ }
25
+ return result .toString ();
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments