454.四数相加II
383. 赎金信
class Solution {
public boolean canConstruct(String ransomNote, String magazine) {
Map<Character, Integer> map1 = new HashMap<>();
Map<Character, Integer> map2 = new HashMap<>();
for (int i = 0; i < magazine.length(); i++) {
if (map1.containsKey(magazine.charAt(i))) {
map1.put(magazine.charAt(i), map1.get(magazine.charAt(i)) + 1);
} else {
map1.put(magazine.charAt(i), 1);
}
}
for (int i = 0; i < ransomNote.length(); i++) {
if (map2.containsKey(ransomNote.charAt(i))) {
map2.put(ransomNote.charAt(i), map2.get(ransomNote.charAt(i)) + 1);
} else {
map2.put(ransomNote.charAt(i), 1);
}
}
boolean result = true;
for (Character key : map2.keySet()) {
if (!map1.containsKey(key))
return false;
else {
if (map1.get(key).intValue() < map2.get(key).intValue()) {
return false;
}
}
}
return true;
}
}```
## 15. 三数之和
## 18. 四数之和