383. 赎金信 发表于 2023-05-08 分类于 代码随想录 阅读次数: 383. 赎金信暴力123456789101112131415bool canConstruct(string ransomNote,string magazine){ for(int i =0;i<magazine.length();i++){ for(int j = 0;j<ransomNote.length();j++){ //在ransomNote中找到和magazine相同的字符 if(magazine[i]==ransomNote[j]){ ransomNote.erase(ransomNote.begin()+j); break; } } } if(ransomNote.length()==0){ return true; } return false;}哈希12345678910111213141516bool canConstruct(string ransomNote,string magazine){ int record[26]={0}; if(ransomNote.size()>magazine.size()){ return false; } for(int i=0;i<magazine.length();i++){ record[magazine[i]-'a']++; } for(int j =0;j<ransomNote.length();j++){ record[ransomNote[j]-'a']--; if(record[ransomNote[j]-'a']<0){ return flae; } } return true;}-------------本文结束感谢您的阅读-------------老板你好,讨口饭吃打赏微信支付支付宝本文作者: 毛本文链接: http://example.com/2023/05/08/383.-赎金信/版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!