-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0929-UniqueEmailAddresses.cs
34 lines (28 loc) · 1015 Bytes
/
0929-UniqueEmailAddresses.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//-----------------------------------------------------------------------------
// Runtime: 108ms
// Memory Usage: 26.6 MB
// Link: https://leetcode.com/submissions/detail/257155145/
//-----------------------------------------------------------------------------
using System.Collections.Generic;
namespace LeetCode
{
public class _0929_UniqueEmailAddresses
{
public int NumUniqueEmails(string[] emails)
{
var hashSet = new HashSet<string>();
foreach (var email in emails)
{
var at_index = email.IndexOf('@');
var local = email.Substring(0, at_index);
var domain = email.Substring(at_index);
var plus_index = local.IndexOf('+');
if (plus_index >= 0)
local = local.Substring(0, plus_index);
local = local.Replace(".", "");
hashSet.Add(local + domain);
}
return hashSet.Count;
}
}
}