Cover image for Classic 150 Interview Questions P383 Ransom Note

Classic 150 Interview Questions P383 Ransom Note


Timeline

Timeline

2025-11-13

init

Hash table

Problem:

Hash table record

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;	}};
Loading comments…