自己写的 很拉 哈哈哈哈哈
class Solution {
public boolean canConstruct(String ransomNote, String magazine) {
if(ransomNote.length()>magazine.length())
return false;
HashMap<Character,Integer> map=new HashMap<>();
for(int i=0;i<magazine.length();i++){
if(map.containsKey(magazine.charAt(i))){
map.put(magazine.charAt(i),map.get(magazine.charAt(i))+1);
}else{
map.put(magazine.charAt(i),1);
}
}
for(int i=0;i<ransomNote.length();i++){
if(map.containsKey(ransomNote.charAt(i))){
int count=map.get(ransomNote.charAt(i))-1;
map.put((char)ransomNote.charAt(i),count);
if(count<=0){
map.remove(ransomNote.charAt(i));
}
}else{
return false;
}
}
return true;
}
}