-
Notifications
You must be signed in to change notification settings - Fork 0
383_RansomNote
a920604a edited this page Apr 14, 2023
·
1 revision
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
int n = ransomNote.size(), m = magazine.size();
if(n>m) return false;
vector<int> vec(26,0);
for(char c:magazine) vec[c-'a']++;
for(char c:ransomNote){
vec[c-'a']--;
if(vec[c-'a']<0) return false;
}
return true;
}
};
- time complexity
O(n)
- space complexity
O(1)
footer