929. Unique Email Addresses

929. Unique Email Addresses

class Solution {
    public int numUniqueEmails(String[] emails) {
        		HashSet emailList = new HashSet();
		for (int i = 0; i < emails.length; i++) {
			String[] sp = emails[i].split("@");
			String address = sp[0];
			String domain = sp[1];
			StringBuilder processed_address = new StringBuilder();
			for (int j = 0; j < address.length(); j++) {
				if (address.charAt(j) != '+')
					break;
				else if (address.charAt(j) != '.')
					processed_address.append(address.charAt(j));
			}
			emailList.add(processed_address + "@" + domain);
		}

		return emailList.size();
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s