https://leetcode-cn.com/problems/ransom-note/solution/java-1ms-da-lao-xie-fa-fei-yuan-chuang-dai-ma-by-f/
很奇妙的想法,膜拜大佬:
class Solution {
public boolean canConstruct(String ransomNote, String magazine) {
if(magazine.length() < ransomNote.length()) return false;
int[] caps = new int[26];
char[] charArray = ransomNote.toCharArray();
for(char c:charArray){
int index = magazine.indexOf(c, caps[c-'a']);
if(index < 0) return false;
caps[c-'a'] = index+1;
}
return true;
}
}