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 }
标签:ransomNote,cnt,return,int,力扣,magazine,赎金,false From: https://www.cnblogs.com/luyj00436/p/17106805.html