LeetCode 3059: Find All Unique Email Domains Solution

Master LeetCode problem 3059 (Find All Unique Email Domains), a easy challenge, with our optimized solutions in Java, C++, and Python. Explore detailed explanations, test your code in our interactive editor, and prepare for coding interviews.

3059. Find All Unique Email Domains

Problem Explanation

Explanation

To find all unique email domains from a list of email addresses, we need to extract the domain part after the "@" symbol and store them in a set to remove duplicates. We can iterate through each email address, split it by "@" to get the domain part, and add it to a set. Finally, we return the set containing unique email domains.

  • Initialize an empty set to store unique email domains.
  • Iterate through each email address in the input list.
  • Split each email address by "@" symbol to retrieve the domain part.
  • Add the domain part to the set.
  • Return the set containing unique email domains.

Time complexity: O(n * m), where n is the number of email addresses and m is the average length of each email address. The splitting operation takes O(m) time. Space complexity: O(n) for storing unique email domains in a set.

Solution Code

import java.util.*;

class Solution {
    public Set<String> findUniqueEmailDomains(List<String> emails) {
        Set<String> uniqueDomains = new HashSet<>();
        for (String email : emails) {
            String domain = email.split("@")[1];
            uniqueDomains.add(domain);
        }
        return uniqueDomains;
    }
}

Try It Yourself

Loading code editor...

Related LeetCode Problems

Frequently Asked Questions

How to solve LeetCode 3059 (Find All Unique Email Domains)?

This page provides optimized solutions for LeetCode problem 3059 (Find All Unique Email Domains) in Java, C++, and Python, along with a detailed explanation and an interactive code editor to test your code.

What is the time complexity of LeetCode 3059 (Find All Unique Email Domains)?

The time complexity for LeetCode 3059 (Find All Unique Email Domains) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.

Can I run code for LeetCode 3059 on DevExCode?

Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 3059 in Java, C++, or Python.

Back to LeetCode Solutions