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

653. Two Sum IV – Input is a BST

653. Two Sum IV – Input is a BST

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
  public boolean findTarget(TreeNode root, int k) {
		ArrayList data = new ArrayList();
		traverers(root, data);
		for (int i  = 0 ; i < data.size() ; i++)
			for (int j  = 0 ; j < data.size() && i!=j ; j++)
				if (data.get(i) + data.get(j) == k)
					return true;

		return false;
	}

	private void traverers(TreeNode root, ArrayList data) {
		if (root != null) {
			data.add(root.val);
			traverers(root.left, data);
			traverers(root.right, data);
		}
	}
}