rachitisthere
BAN USERint[] solve(int[] input) {
int[] output = new int[input.length];
int product = 1;
for (int i = 0; i < input.length; i++) {
output[i] = product;
product = product * input[i];
}
product = 1;
for (int i = input.length - 1; i >= 0; i--) {
output[i] = output[i] * product;
product = product * input[i];
}
return output;
}
public static void Test_0() {
Map<String, String[]> map = Maps.newHashMap();
map.put("2", new String[]{"A", "B", "C"});
map.put("3", new String[]{"D", "E", "F"});
map.put("4", new String[]{"G", "H", "I"});
map.put("5", new String[]{"J", "K", "L"});
map.put("6", new String[]{"M", "N", "O"});
map.put("7", new String[]{"P", "Q", "R", "S"});
map.put("8", new String[]{"T", "U", "V"});
map.put("9", new String[]{"W", "X", "Y", "Z"});
String input = "4255387856";
List answer = solve(map, input, Lists.newArrayList(""));
System.out.println(answer.size());
}
private static List<String> solve(Map<String, String[]> map, String input, List<String> current) {
if ((input == null) || (input.isEmpty())) {
return current;
}
String[] values = map.get(input.charAt(0) + "");
List<String> next = Lists.newArrayList();
for (String choice : current) {
for (String value : values) {
next.add(choice + value);
}
}
return solve(map, input.substring(1), next);
}
boolean solve(String[] input) {
Set<String> dict = Sets.newHashSet();
for (String elem : input) {
char[] array = elem.toCharArray();
Arrays.sort(array);
String target = new String(array);
if (dict.contains(target)) {
return true;
} else {
dict.add(target);
}
}
return false;
}
boolean OneEditApart(String first, String second) {
String small = (first.length() <= second.length()) ? first : second;
String large = (first.length() <= second.length()) ? second : first;
int lengthDiff = large.length() - small.length();
if (lengthDiff > 1) {
return false;
} else if (lengthDiff == 0) {
int diffs = 0;
for (int i = 0; i < small.length(); i++) {
if ((small.charAt(i) != large.charAt(i))) {
diffs++;
}
}
return (diffs > 1) ? false : true;
} else if (lengthDiff == 1) {
if (small.equals(large.substring(1))) {
return true;
}
if (small.equals(large.substring(0, large.length() - 2))) {
return true;
}
return false;
}
return false;
}
- rachitisthere October 20, 2014