【力扣】赎金信
https://leetcode.cn/problems/ransom-note/submissions/
1 class Solution { 2 public boolean canConstruct(String ransomNote, String magazine) { 3 // 两个字符串长度不一样,则返回true 4 if(ransomNote.length() > magazine.length()){ 5 return false; 6 } 7 int[] cnt = new int[26]; 8 for (char c : magazine.toCharArray()) { 9 cnt[c - 'a']++; 10 } 11 for (char c : ransomNote.toCharArray()) { 12 cnt[c - 'a']--; 13 if(cnt[c - 'a'] < 0) { 14 return false; 15 } 16 } 17 return true; 18 } 19 }
有志者,事竟成,破釜沉舟,百二秦关终属楚; 苦心人,天不负,卧薪尝胆,三千越甲可吞吴。