# [217\. Contains Duplicate](https://leetcode.com/problems/contains-duplicate/) :::spoiler Solution HashMap ```cpp= class Solution { public: bool containsDuplicate(vector<int>& nums) { unordered_map<int, int> freq; for (auto num : nums) ++freq[num]; for (auto [k, v] : freq) { if (v > 1) return true; } return false; } }; ``` - 時間複雜度:$O(n)$ - 空間複雜度:$O(n)$ :::
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up