0%

383. 赎金信

383. 赎金信

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
int map[26]{ 0 };
for(auto ch : magazine)
++map[ch - 'a'];
for(auto ch : ransomNote)
--map[ch - 'a'];
for(int i = 0; i < 26; ++i)
if(map[i] < 0)
return false;
return true;
}
};