For simplicity, it is checking whether the characters in a string (that needs to be created) are present in a larger string (dictionary). Would a character array of the letters make sense here, or would it be better with a Map<Character, Integer>
?
public class RansomNoteProblem {
public static void main (String args[]){
String blob = "thisisanothwllowllqend";
String note = "thisisanotex";
System.out.println(validateLetterCreation(blob,note));
}
public static boolean validateLetterCreation(String dict, String note){
int charArray[] = new int[256];
for(int i=0;i<dict.length();i++){
int charValue = (int)dict.charAt(i);
charArray[charValue]++;
}
for(int i=0;i<note.length();i++){
int charValue = note.charAt(i);
if(charArray[charValue]<=0){
return false;
}
else {
charArray[charValue]--;
}
}
return true;
}
}