Cover image for 面试经典150题 P383 赎金信

面试经典150题 P383 赎金信


时间轴

时间轴

2025-11-13

init

哈希表

题目:

哈希表记录

12345678910111213141516171819202122232425
#include <string>#include <unordered_map>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;	}};
评论加载中…