用int array记录可用字母数量
0的时候说明GG了public boolean canConstruct(String ransomNote, String magazine) { if(ransomNote.length() > magazine.length()) return false; int[] letters = new int[26]; for(int n = 0; n < magazine.length();n++) { letters[magazine.charAt(n) - 'a']++; } for(int n = 0; n < ransomNote.length();n++) { if(letters[ransomNote.charAt(n) -'a'] != 0) letters[ransomNote.charAt(n)-'a']--; else return false; } return true; }