面试经典150题 P383 赎金信
时间轴
2025-11-13
init
题目:
哈希表记录1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using std::string;
using std::unordered_map;
class Solution {
public:
bool canConstruct(string ransomNote, string magazine)
{
unordered_map<char, int> uset;
for (auto &ch : magazine) {
uset[ch]++;
}
for (auto &ch : ransomNote) {
if (!uset.count(ch)) {
return false;
}
if (uset[ch] == 0) {
return false;
}
uset[ch]--;
}
return true;
}
};
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 常想一二,不思八九!
评论





