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();
    }
}

819. Most Common Word

819. Most Common Word

import java.util.Hashtable;
import java.util.List;
import java.util.Set;
class Solution {
    public String mostCommonWord(String paragraph, String[] banned) {
	String paragraphProcessed = paragraph.replace("!", "").replace("?", "").replace("'", "").replace(",", "").replaceAll(";", "").replace(".", "");

		String input[] = paragraphProcessed.split(" ");
		for (int i = 0; i < input.length; i++)
			input[i] = input[i].toLowerCase();
		Hashtable f = new Hashtable();
		for (String s : input) {
			if (f.get(s) == null)
				f.put(s, 1);
			else
				f.replace(s, f.get(s) + 1);
		}

		for (int i = 0; i < banned.length; i++) {
			if (f.get(banned[i]) != null)
				f.remove(banned[i]);
		}

		int mostFrequ = Integer.MIN_VALUE;
		String mostFrequString = "";
		Set keys = f.keySet();
		for (String key : keys) {
			if (f.get(key) > mostFrequ) {
				mostFrequ = f.get(key);
				mostFrequString = key;
			}
		}
		return mostFrequString;
	}
}