class Solution {
public boolean canConstruct(String ransomNote, String magazine) {
HashMap<Character,Integer> magMap=new HashMap<>();
char[] mag=magazine.toCharArray();
for(char c:mag){
if(!magMap.containsKey(c))
magMap.put(c,1);
else magMap.put(c,magMap.get(c)+1);
}
char[] ransom=ransomNote.toCharArray();
for(char c:ransom){
if(magMap.getOrDefault(c,0)==0)
return false;
else magMap.put(c,magMap.get(c)-1);
}
return true;
}
}
08-18
08-18
08-18
09-06