blob: 1a78e07a42cfb4a6f0cbcbbbc3b2dc27c000df83 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include "leetcode.h"
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
int count[26] = {0};
for (char ch : magazine)
count[ch - 'a']++;
for (char ch : ransomNote)
if (count[ch - 'a']-- <= 0)
return false;
return true;
}
};
int main() {
Solution obj;
string ransomNote = "a", magazine = "b";
if (obj.canConstruct(ransomNote, magazine))
cout << "true";
else
cout << "false";
}
|