leetcode/notes/src/hash_table.md
2023-02-28 17:30:18 +08:00

12 lines
410 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 总结
当我们需要判断某个元素是否出现过时,考虑用哈希表。
## unordered_map 与 unordered_set
这俩的底层都是用哈希函数实现的,因此访问其中的元素可以达到 O(1) 的时间复杂度。
它们的区别在于unordered_map 存储的是 key-value ,而 unordered_set 只存储 key 。
一般我们直接用 unordered_map 就可以完成所有操作了。