struct pair_hash
{
template<class T1, class T2>
std::size_t operator() (const std::pair<T1, T2>& p) const
{
auto h1 = std::hash<T1>{}(p.first);
auto h2 = std::hash<T2>{}(p.second);
return h1 ^ h2;
}
};
unordered_map<pair<int, bool>, int, pair_hash> Map;
今天为了写leetcode 的每日一题《391. 完美矩形》,想到需要使用hash存储矩形内部的点,需要使用到pair和unordered_map,就查询了一下,在此记录。
本文介绍了如何在解决LeetCode题目时,利用pair_hash模板函数实现对pair类型的键的unordered_map,以存储和处理矩形内部点问题,展示了pair和哈希函数在数据结构中的应用技巧。

1355

被折叠的 条评论
为什么被折叠?



