代码实现:
public class CanConstruct {
public static void main(String[] args) {
CanConstruct canConstruct = new CanConstruct();
System.out.println(canConstruct.canConstruct("aa","ab"));
}
public boolean canConstruct(String ransomNote, String magazine) {
int[] arr = new int[26];
for (int i = 0; i < magazine.length(); i++){
char temp = magazine.charAt(i);
arr[temp - 'a'] ++;
}
for (int i = 0; i < ransomNote.length(); i++){
char temp = ransomNote.charAt(i);
if (arr[temp - 'a'] <= 0){
return false;
}
arr[temp - 'a']--;
}
return true;
}
}



