# Leetcode 217. Contains Duplicate ###### tags: `Leetcode(C++)` 題目 : https://leetcode.com/problems/contains-duplicate/ 想法 : 用MAP做,時間複雜度爆炸了,但還是AC ? . ? 時間複雜度 : O(nlogn)。 程式碼 : ``` class Solution { public: bool containsDuplicate(vector<int>& nums) { bool ok = 0; int l = nums.size(); map<int,int> m; for(int i = 0 ; i < l ; i++){ m[nums[i]]++; } map<int,int>::iterator it; for(it = m.begin() ; it != m.end() && !ok ; it++){ //cout << it -> second << " "; if(it -> second >= 2) ok = 1; } return ok; } }; ```
×
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