383. 赎金信

 1 class Solution 
 2 {
 3 public:
 4     bool canConstruct(string ransomNote, string magazine) 
 5     {
 6         unordered_map<char,int> hash_r,hash_m;
 7         for(auto a : magazine) hash_m[a] ++;
 8         for(auto a : ransomNote) hash_r[a] ++;
 9         for(auto a : hash_r)
10         {
11             if(a.second > hash_m[a.first]) return false;
12         }
13         return true;
14     }
15 };

 

posted @ 2020-04-27 14:20  Jinxiaobo0509  阅读(90)  评论(0)    收藏  举报