Leetcode 383 Ransom Note
#include <string>
#include <vector>
using namespace std;
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
vector <int> ransomNoteFreq(26);
vector <int> magazineFreq(26);
for (int i = 0; i < ransomNote.size(); i++){
ransomNoteFreq[ransomNote[i] - 'a']++;
}
for (int i = 0; i <magazine.size(); i++){
magazineFreq[magazine[i] - 'a']++;
}
for (int i = 0; i < ransomNoteFreq.size(); i++){
if (ransomNoteFreq[i] > magazineFreq[i])
return false;
}
return true;
}
};