Skip to content

Commit 394d0ed

Browse files
committed
contains-duplicate solution
1 parent b5a7286 commit 394d0ed

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

contains-duplicate/sungjinwi.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
set를 통해 중복제거를 한 후 기존 nums와 길이 비교
3+
4+
nums의 길이 N
5+
6+
TC : O(N)
7+
set를 만드는 데 전체 순회하며 N 시간 소모
8+
9+
SC : O(N)
10+
set 만들 때 N의 메모리 할당
11+
*/
12+
#include <vector>
13+
#include <unordered_set>
14+
using namespace std;
15+
16+
class Solution {
17+
public:
18+
bool containsDuplicate(vector<int>& nums) {
19+
unordered_set<int> us(nums.begin(), nums.end());
20+
if (nums.size() == us.size())
21+
return false;
22+
else
23+
return true;
24+
}
25+
};

0 commit comments

Comments
 (0)