383.赎金信、454. 四数相加-II
383.赎金信-Easy
状态:已完成
// 383.赎金信
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
int record[26] = {0};
if(ransomNote.size() > magazine.size()){
return false;
}
for(int i = 0; i < magazine.size(); i++){
record[magazine[i] - 'a']++;
}
for(int i = 0; i < ransomNote.size(); i++){
record[ransomNote[i] - 'a']--;
if(record[ransomNote[i] - 'a'] < 0){
return false;
}
}
return true;
}
};
454. 四数相加-II-Easy
状态:已完成
// 454. 四数相加-II
class Solution {
public:
int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {
unordered_map<int, int> map;
for(int a : nums1){
for(int b : nums2){
map[a + b]++;
}
}
int count = 0;
for(int c : nums3){
for(int d : nums4){
if(map.find(0 - (c + d)) != map.end()){
count += map[0 - (c + d)];
}
}
}
return count;
}
};