import java.util.Map;import java.util.HashMap;public class Solution { static boolean canConstruct(String ransomNote, String magazine) { Map<Character, Integer> characterMap = new HashMap<>(); for (int i = 0; i < magazine.length(); i++) { int characterCount = characterMap.getOrDefault( magazine.charAt(i), 0); characterMap.put(magazine.charAt(i), characterCount + 1); } for (int i = 0; i < ransomNote.length(); i++) { int characterCount = characterMap.getOrDefault( ransomNote.charAt(i), 0); if (characterCount == 0) { return false; } characterMap.put(ransomNote.charAt(i), characterCount - 1); } return true; } public static void main(String[] args) { String ransomNote1 = "a"; String magazine1 = "b"; String ransomNote2 = "aa"; String magazine2 = "ab"; String ransomNote3 = "aa"; String magazine3 = "aab"; System.out.println(canConstruct(ransomNote1, magazine1)); System.out.println(canConstruct(ransomNote2, magazine2)); System.out.println(canConstruct(ransomNote3, magazine3)); }}